Ubuntu – Configure connection sharing with specific IP Address

connection-sharingnetworking

Edit – a more concise version of the question:

When using connection sharing, I want network manager to use the 192.168.254 subnet instead of the 10.42.0 subnet. Is this possible?

Background:

I need to share my wireless internet connection (on an Ubuntu laptop) with a RasPi connected to the laptop by ethernet.

Everything works fine by configuring eth0 as "Shared to Other Computers" (documented in many places, for example here).

Using this setup, my IP address when connected to the RasPi is 10.42.0.1. The RasPi picks up another address in that subnet. Everything works great!

Because of how the RasPi is configured (to work with several other systems), I want eth0 to use 192.168.254.1. If I configure eth0 to manually use 192.168.254.1:
Manual eth0 configuration

the RasPi connects to my laptop and I am able to ssh into it. However, although I still see a valid wlan0 configuration when running ifconfig, I'm unable to access the internet (presumably my laptop is trying to use eth0 instead of wlan0).

I'm looking for a way to either:

a) Still use wlan0 to access the internet when eth0 is manually configured

b) Force eth0 to use a specific IP address when configured with "Shared to Other Computers"

I'm trying to set up simple instructions for other users, so if possible I'd like to avoid any manual iptables-type setups.

Best Answer

In versions before 1.4.2, 10.42.0.x is hard-coded into NetworkManager. Forget about GUI-based solution or wait until the bug/feature request is fixed. Or fix it yourself for all of us. Or at least vote the bug on launchpad for faster resolution.

Either upgrade to Ubuntu 17.04, with version 1.4.4, or use the following command from Thomas Haller to set the host IP and class.

nmcli connection modify $CONNECTION_ID +ipv4.addresses 192.168.5.1/24

where $CONNECTION_ID if found via nmcli connection show. Afterwards, verify with nmcli connection show $CONNECTION_ID.

Related Question