{"id":7612,"date":"2020-09-18T21:11:00","date_gmt":"2020-09-18T19:11:00","guid":{"rendered":"https:\/\/monodes.com\/predaelli\/?p=7612"},"modified":"2020-09-18T17:11:43","modified_gmt":"2020-09-18T15:11:43","slug":"internet-connection-sharing-with-networkmanager-fedora-magazine","status":"publish","type":"post","link":"https:\/\/monodes.com\/predaelli\/2020\/09\/18\/internet-connection-sharing-with-networkmanager-fedora-magazine\/","title":{"rendered":"Internet connection sharing with NetworkManager &#8211; Fedora Magazine"},"content":{"rendered":"<p><em><a href=\"https:\/\/fedoramagazine.org\/internet-connection-sharing-networkmanager\/\">Internet connection sharing with NetworkManager &#8211; Fedora Magazine<\/a><\/em><\/p>\n<p>Or <code class=\"\" data-line=\"\">nmtui<\/code>, <code class=\"\" data-line=\"\">nmcli<\/code> and other commands for the shell wizard<\/p>\n<p><!--more--><!--nextpage--><\/p>\n<blockquote>\n<h1 class=\"post-title\">Internet connection sharing with NetworkManager<\/h1>\n<div class=\"post-meta\"><span class=\"resp\">Posted<\/span> <span class=\"post-meta-author\"> by <a class=\"author url fn\" title=\"Posts by Beniamino Galvani\" href=\"https:\/\/fedoramagazine.org\/author\/bengal\/\" rel=\"author\">Beniamino Galvani<\/a> <\/span> <span class=\"post-meta-date\">on <a href=\"https:\/\/fedoramagazine.org\/internet-connection-sharing-networkmanager\/\">June 17, 2020<\/a><\/span><\/div>\n<div>\n<p>NetworkManager is the network configuration daemon used on Fedora and many other distributions. It provides a consistent way to configure network interfaces and other network-related aspects on a Linux machine. Among many other features, it provides a Internet connection sharing functionality that can be very useful in different situations.<\/p>\n<p>F<mark id=\"annotation-text-50da97d1-a97d-473a-89d4-b410ed9c0cc9\" class=\"annotation-text annotation-text-yoast\"><\/mark>or example, suppose you are in a place without Wi-Fi and want to share your laptop\u2019s mobile data connection with friends. Or maybe you have a laptop with broken Wi-Fi and want to connect it via Ethernet cable to another laptop; in this way the first laptop become able to reach the Internet and maybe download new Wi-Fi drivers.<\/p>\n<p>In cases like these it is useful to share Internet connectivity with other devices. On smartphones this feature is called \u201cTethering\u201d and allows sharing a cellular connection via Wi-Fi, Bluetooth or a USB cable.<\/p>\n<p>This article shows how the connection sharing mode offered by NetworkManager can be set up easily; it addition, it explains how to configure some more advanced features for power users.<\/p>\n<p><span id=\"more-31179\"><\/span><\/p>\n<h2>How connection sharing works<\/h2>\n<p>The basic idea behind connection sharing is that there is an <em>upstream<\/em> interface with Internet access and a <em>downstream<\/em> interface that needs connectivity. These interfaces can be of a different type\u2014for example, Wi-Fi and Ethernet.<\/p>\n<p>If the upstream interface is connected to a LAN, it is possible to configure our computer to act as a <em>bridge<\/em>; a bridge is the software version of an Ethernet switch. In this way, you \u201cextend\u201d the LAN to the downstream network. However this solution doesn\u2019t always play well with all interface types; moreover, it works only if the upstream network uses private addresses.<\/p>\n<p>A more general approach consists in assigning a private IPv4 subnet to the downstream network and turning on routing between the two interfaces. In this case, NAT (Network Address Translation) is also necessary. The purpose of NAT is to modify the source of packets coming from the downstream network so that they look as if they originate from your computer.<\/p>\n<p>It would be inconvenient to configure manually all the devices in the downstream network. Therefore, you need a DHCP server to assign addresses automatically and configure hosts to route all traffic through your computer. In addition, in case the sharing happens through Wi-Fi, the wireless network adapter must be configured as an access point.<\/p>\n<p>There are many tutorials out there explaining how to achieve this, with different degrees of difficulty. NetworkManager hides all this complexity and provides a <em>shared<\/em> mode that makes this configuration quick and convenient.<\/p>\n<h2>Configuring connection sharing<\/h2>\n<p>The configuration paradigm of NetworkManager is based on the concept of connection (or connection profile). A connection is a group of settings to apply on a network interface.<\/p>\n<p>This article shows how to create and modify such connections using <em>nmcli<\/em>, the NetworkManager command line utility, and the GTK connection editor. If you prefer, other tools are available such as <em>nmtui<\/em> (a text-based user interface), GNOME control center or the KDE network applet.<\/p>\n<p>A reasonable prerequisite to share Internet access is to have it available in the first place; this implies that there is already a NetworkManager connection active. If you are reading this, you probably already have a working Internet connection. If not, see <a href=\"https:\/\/www.redhat.com\/sysadmin\/becoming-friends-networkmanager\">this article<\/a> for a more comprehensive introduction to NetworkManager.<\/p>\n<p>The rest of this article assumes you already have a Wi-Fi connection profile configured and that connectivity must be shared over an Ethernet interface <em>enp1s0<\/em>.<\/p>\n<p>To enable sharing, create a connection for interface enp1s0 and set the ipv4.method property to <em>shared <\/em>instead of the usual <em>auto<\/em>:<\/p>\n<pre class=\"wp-block-preformatted\">$ nmcli connection add type ethernet ifname enp1s0 ipv4.method shared con-name local<\/pre>\n<p>The shared IPv4 method does multiple things:<\/p>\n<ul>\n<li>enables IP forwarding for the interface;<\/li>\n<li>adds firewall rules and enables masquerading;<\/li>\n<li>starts dnsmasq as a DHCP and DNS server.<\/li>\n<\/ul>\n<p>NetworkManager connection profiles, unless configured otherwise, are activated automatically. The new connection you have added should be already active in the device status:<\/p>\n<pre class=\"wp-block-preformatted\">$ nmcli device\nDEVICE &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; TYPE&nbsp; &nbsp;&nbsp;&nbsp; STATE &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; CONNECTION\nenp1s0 &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; ethernet&nbsp; connected &nbsp;&nbsp;&nbsp; local\nwlp4s0 &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; wifi&nbsp; &nbsp;&nbsp;&nbsp; connected &nbsp;&nbsp;&nbsp; home-wifi<\/pre>\n<p>If that is not the case, activate the profile manually with <em>nmcli connection up local<\/em>.<\/p>\n<h2>Changing the shared IP range<\/h2>\n<p>Now look at how NetworkManager configured the downstream interface enp1s0:<\/p>\n<pre class=\"wp-block-preformatted\">$ ip -o addr show enp1s0\n8: enp1s0 inet 10.42.0.1\/24 brd 10.42.0.255 ...<\/pre>\n<p>10.42.0.1\/24 is the default address set by NetworkManager for a device in shared mode. Addresses in this range are also distributed via DHCP to other computers. If the range conflicts with other private networks in your environment, change it by modifying the <em>ipv4.addresses<\/em> property:<\/p>\n<pre class=\"wp-block-preformatted\">$ nmcli connection modify local ipv4.addresses 192.168.42.1\/24<\/pre>\n<p>Remember to activate again the connection profile after any change to apply the new values:<\/p>\n<pre class=\"wp-block-preformatted\">$ nmcli connection up local\n\n$ ip -o addr show enp1s0\n8: enp1s0 inet 192.168.42.1\/24 brd 192.168.42.255 ...<\/pre>\n<p>If you prefer using a graphical tool to edit connections, install the <em>nm-connection-editor<\/em> package. Launch the program and open the connection to edit; then select the <em>Shared to other computers<\/em> method in the <em>IPv4 Settings<\/em> tab. Finally, if you want to use a specific IP subnet, click <em>Add<\/em> and insert an address and a netmask.<\/p>\n<figure class=\"wp-block-gallery columns-1 is-cropped\">\n<ul class=\"blocks-gallery-grid\">\n<li class=\"blocks-gallery-item\">\n<figure><a href=\"https:\/\/fedoramagazine.org\/internet-connection-sharing-networkmanager\/\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"alignnone size-full\" src=\"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2020\/09\/nmce.png?w=910&#038;ssl=1\" alt=\"\"\/><\/a><\/figure>\n<\/li>\n<\/ul>\n<\/figure>\n<h2>Adding custom dnsmasq options<\/h2>\n<p>In case you want to further extend the dnsmasq configuration, you can add new configuration snippets in <em>\/etc\/NetworkManager\/dnsmasq-shared.d\/<\/em>. For example, the following configuration:<\/p>\n<pre class=\"wp-block-preformatted\">dhcp-option=option:ntp-server,192.168.42.1\ndhcp-host=52:54:00:a4:65:c8,192.168.42.170<\/pre>\n<p>tells dnsmasq to advertise a NTP server via DHCP. In addition, it assigns a static IP to a client with a certain MAC.<\/p>\n<p>There are many other useful options in the dnsmasq manual page. However, remember that some of them may conflict with the rest of the configuration; so please use custom options only if you know what you are doing.<\/p>\n<h2>Other useful tricks<\/h2>\n<p>If you want to set up sharing via Wi-Fi, you could create a connection in Access Point mode, manually configure the security, and then enable connection sharing. Actually, there is a quicker way, the hotspot mode:<\/p>\n<pre class=\"wp-block-preformatted\">$ nmcli device wifi hotspot [ifname $dev] [password $pw]<\/pre>\n<p>This does everything needed to create a functional access point with connection sharing. The interface and password options are optional; if they are not specified, <em>nmcli<\/em> chooses the first Wi-Fi device available and generates a random password. Use the \u2018<em>nmcli device wifi show-password<\/em>\u2018 command to display information for the active hotspot; the output includes the password and a text-based QR code that you can scan with a phone:<\/p>\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/fedoramagazine.org\/internet-connection-sharing-networkmanager\/\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"alignnone size-full\" src=\"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2020\/09\/hotspot-password.png?w=910&#038;ssl=1\" alt=\"\"\/><\/a><\/figure>\n<h2>What about IPv6?<\/h2>\n<p>Until now this article discussed sharing IPv4 connectivity. NetworkManager also supports sharing IPv6 connectivity through DHCP prefix delegation. Using prefix delegation, a computer can request additional IPv6 prefixes from the DHCP server. Those public routable addresses are assigned to local networks via Router Advertisements. Again, NetworkManager makes all this easier through the shared IPv6 mode:<\/p>\n<pre class=\"wp-block-preformatted\">$ nmcli connection modify local ipv6.method shared<\/pre>\n<p>Note that IPv6 sharing requires support from the Internet Service Provider, which should give out prefix delegations through DHCP. If the ISP doesn\u2019t provides delegations, IPv6 sharing will not work; in such case NM will report in the journal that no prefixes are available:<\/p>\n<pre class=\"wp-block-preformatted\">policy: ipv6-pd: none of 0 prefixes of wlp1s0 can be shared on enp1s0<\/pre>\n<p>Also, note that the Wi-Fi hotspot command described above only enables IPv4 sharing; if you want to also use IPv6 sharing you must edit the connection manually.<\/p>\n<h2>Conclusion<\/h2>\n<p>Remember, the next time you need to share your Internet connection, NetworkManager will make it easy for you.<\/p>\n<p>If you have suggestions on how to improve this feature or any other feedback, please reach out to the NM community using the <a href=\"https:\/\/mail.gnome.org\/mailman\/listinfo\/networkmanager-list\">mailing list<\/a>, the <a href=\"https:\/\/gitlab.freedesktop.org\/NetworkManager\/NetworkManager\/-\/issues\">issue tracker<\/a> or joining the <em>#nm<\/em> IRC channel on <em>freenode<\/em>.<\/p>\n<\/div>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">Internet connection sharing with NetworkManager &#8211; Fedora Magazine Or nmtui, nmcli and other commands for the shell wizard<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/monodes.com\/predaelli\/2020\/09\/18\/internet-connection-sharing-with-networkmanager-fedora-magazine\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"link","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[72],"tags":[],"class_list":["post-7612","post","type-post","status-publish","format-link","hentry","category-documentations","post_format-post-format-link"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6daft-1YM","jetpack-related-posts":[{"id":6804,"url":"https:\/\/monodes.com\/predaelli\/2020\/03\/02\/how-to-join-a-domain-from-fedora-31\/","url_meta":{"origin":7612,"position":0},"title":"How to join a domain from Fedora 31","author":"Paolo Redaelli","date":"2020-03-02","format":false,"excerpt":"Once it was black magic, nowadays it is so simple: Join in Active Directory Domain 2019\/11\/12 I suspect it could have been simpler if I followed the installer, but I preferred to go on my own. \u00a0 \u00a0 Join in Windows Active Directory Domain with Realmd. This tutorial needs Windows\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10388,"url":"https:\/\/monodes.com\/predaelli\/2023\/04\/21\/the-immutables-fedora-silverblu-endlessos-and-vanillaos\/","url_meta":{"origin":7612,"position":1},"title":"The immutables: Fedora Silverblu, EndlessOS and VanillaOS","author":"Paolo Redaelli","date":"2023-04-21","format":false,"excerpt":"Browsing How to rebase to Fedora Linux 38 on Silverblue - from Fedora Magazine I just discovered that Fedora Silverblue is a new variant of Fedora Workstation with rpm-ostree at its core to provide fully atomic upgrades.\u00a0 Furthermore, Fedora Silverblue is immutable and upgrades as a whole, providing easy rollbacks\u2026","rel":"","context":"In &quot;Debian&quot;","block_context":{"text":"Debian","link":"https:\/\/monodes.com\/predaelli\/category\/debian\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8303,"url":"https:\/\/monodes.com\/predaelli\/2021\/03\/31\/how-to-upgrade-from-fedora-32-to-fedora-33\/","url_meta":{"origin":7612,"position":2},"title":"How To Upgrade From Fedora 32 To Fedora 33","author":"Paolo Redaelli","date":"2021-03-31","format":false,"excerpt":"How To Upgrade From Fedora 32 To Fedora 33 [CLI & Graphical Methods] | Linux Journal It's so simple with the GUI, but I'm a shell guy, so $ sudo dnf upgrade --refresh $ sudo dnf install dnf-plugin-system-upgrade $ sudo dnf system-upgrade download --releasever=33 $ sudo dnf system-upgrade reboot","rel":"","context":"In &quot;Fedora - RedHat&quot;","block_context":{"text":"Fedora - RedHat","link":"https:\/\/monodes.com\/predaelli\/category\/fedora-redhat\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5226,"url":"https:\/\/monodes.com\/predaelli\/2019\/02\/14\/you-can-now-build-a-risc-v-pc-that-runs-fedora-linux-with-an-fpga\/","url_meta":{"origin":7612,"position":3},"title":"You Can Now Build a RISC-V PC That Runs Fedora Linux with an FPGA","author":"Paolo Redaelli","date":"2019-02-14","format":"status","excerpt":"https:\/\/blog.hackster.io\/you-can-now-build-a-risc-v-pc-that-runs-fedora-linux-with-an-fpga-97cd5789b28?fbclid=IwAR0TrxxFqWlxARY0y3jSM9su8XOHJMQosBdcdxF05SZvxwaYY7ZSuRZ3k90 I can't wait to see a complete system using RISC-V","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7161,"url":"https:\/\/monodes.com\/predaelli\/2020\/05\/04\/7161\/","url_meta":{"origin":7612,"position":4},"title":"rdiff-backup","author":"Paolo Redaelli","date":"2020-05-04","format":"link","excerpt":"rdiff-backup Reverse differential backup tool, over a network or locally. Comfortably installable on your Debian\/Ubuntu with sudo apt install rdiff-backup\u00a0and on Fedora with sudo dnf install rdiff-backup","rel":"","context":"In &quot;Software&quot;","block_context":{"text":"Software","link":"https:\/\/monodes.com\/predaelli\/category\/software\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3388,"url":"https:\/\/monodes.com\/predaelli\/2017\/09\/27\/epiphany-on-centos-7\/","url_meta":{"origin":7612,"position":5},"title":"Epiphany on CentOS 7","author":"Paolo Redaelli","date":"2017-09-27","format":false,"excerpt":"I'm quite puzzeled: Centos 7 contains the same software as RedHat so knowing that Red Hat is one of the forces behind Gnome one would expect to find Web, the browser once known as Epiphany to be installed or at least installable on it. Nope. As I discoverede reading Gnome\u2026","rel":"","context":"In &quot;Fedora - RedHat&quot;","block_context":{"text":"Fedora - RedHat","link":"https:\/\/monodes.com\/predaelli\/category\/fedora-redhat\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/7612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/comments?post=7612"}],"version-history":[{"count":0,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/7612\/revisions"}],"wp:attachment":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/media?parent=7612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/categories?post=7612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/tags?post=7612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}