Internet connection sharing with NetworkManager

With this recipe we will create a wireless access point in our laptop to share our wired Internet connection. This is quite useful where you only have a wired Internet connection (e.g. my work place) for giving access to your phone.

This is done in Fedora 25 Workstation with NetworkManager.

In my laptop I have two network interfaces: enp1s0 for the wired ethernet and wlp2s0 for the wireless. I also have the default firewall configuration (all interfaces are in the default zone FedoraWorkstation).

We have to create the hotspot connection in NetworkManager. Change the PSK password to something more secure.

# nmcli connection add con-name Hotspot autoconnect no ifname wlp2s0 type wifi connection.zone trusted 802-11-wireless.mode ap 802-11-wireless.ssid my-AP 802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.proto rsn 802-11-wireless-security.pairwise ccmp 802-11-wireless-security.psk 12345678 ipv4.method shared ipv6.method ignore

Connection 'Hotspot' (c5fcb9b1-4d90-4847-9467-335315ba2288) successfully added.

The magic here happens with ipv4.method=shared, as NetworkManager launches a dnsmasq process and creates the appropriate NAT rules automatically.

Now you can enable/disable the hotspot with one command:

# nmcli connection up Hostspot
# nmcli connection down Hotspot

2016/11/24 Edit: Replace the script with ipv4.method=shared. Thanks to Lubomir Rintel for the tip.

Advertisements

5 thoughts on “Internet connection sharing with NetworkManager”

  1. thanks for this. i have a need for the opposite situation. i will use the wifi to the LAN but I need the wired on my laptop to share out to other devices (or via a switch). I guess I need to change the type in the command above. i will experiment that soon. I am on F25 now.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s