18

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.

jake
  • 449
  • 2
  • 4
  • 12
  • It's kind of hard to do. I can't put a guide here right now, but I'll edit it in later. Try here: https://www.howtoforge.com/linux-basics-set-a-static-ip-on-ubuntu – TheWanderer Apr 15 '15 at 16:15
  • As a side note for Raspberry Pi networking (or similar) it's worth making a note of the device's link-local IPv6 address so you can still SSH to it if you screw up the IPv4 configuration. – Rodney Apr 26 '23 at 13:21

2 Answers2

20

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.

Lucas
  • 665
Adam Ryczkowski
  • 4,403
  • 9
  • 40
  • 65
  • 2
    apparently, the bug was fixed on 14. September 2016! It is now possible to configure it through the GUI, but it will take time for this to trickle down into releases of course. – hoijui Jun 24 '17 at 08:53
  • This was fixed in network-manager 1.4.2. Ubuntu 17.04 has 1.4.4. I asked Canonical to backport this to 16.04 LTS. https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1098362/comments/8 – Lucas Sep 26 '17 at 19:17
  • 4
    And how do we do it o newer versions? – leo Oct 18 '17 at 13:54
  • 1
    20.04.1 LTS supports gui config out of the box... just set your ip and gateway to yourself... done! I unplugged and plugged back in... but an ip link eno2 down && ip link eno2 up should do it also – Ray Foss Sep 17 '20 at 01:34
  • 1
    @RayFoss Interesting, in my install of 20.04, the moment I select that I want to share the connection it removes the option to set an IP address. I had to go back to setting it from the console. – Peter Jan 23 '21 at 03:44
  • 2
    So what is the actual way to do it right in the fixed gui? – Mehdi Mar 15 '21 at 17:43
  • This is still an issue in KDE. – Rodney Apr 26 '23 at 13:19
-2

Your configuration has a fundamental problem. Your gateway is set to the same IP address as your local IP address.

A graphic: Raspi: connect to 10.0.0.5 Raspi: not in my subnet, send to gateway Raspi receives request again and responds with the same message.

Your question is a bit confusing, but it seems that your laptop should have an IP like 192.168.254.2

You will also need to set up Network Address Translation on the laptop.

I think it would be better if you bridged the two interfaces, so the raspi will effectively use your laptop's wifi to communicate. On your laptop, do:

sudo -i

This makes you root.

apt-get update
apt-get install bridge-utils
brctl addbr br0
brctl addif br0 wlan0
brctl addif br0 eth0
ifconfig br0 10.42.0.1
ifconfig br0 netmask 255.0.0.0
ifconfig br0 up

Ctrl-D to exit root

On raspi(connected to eth0):

sudo ifconfig eth0 10.42.0.2
sudo ifconfig eth0 netmask 255.0.0.0
sudo ifconfig eth0 up
echo 'nameserver 8.8.8.8'>/etc/resolv.conf
ping 10.42.0.1
ping 8.8.8.8
ping fb.com

The final three commands will show you what type of network access you have:

  • If only the first passes: local network
  • If up to the second passes: Internet access
  • If all pass: Internet access with DNS
hoijui
  • 153
Wilhelm Erasmus
  • 728
  • 5
  • 24
  • I'm not sure what you mean about my gateway/address. When I'm sharing my connection, isn't my laptop the gateway for the RasPi? In the manual configuration I showed in the OP, the RasPi picks up 192.168.254.100 - I have no problems being unable to communicate due to different subnets. – jake Apr 15 '15 at 19:39
  • A better way of phrasing the question might be: when sharing my connection, I want network manager to use the 192.168.254 subnet instead of the 10.42.0 subnet – jake Apr 15 '15 at 19:41
  • @jake your laptop is indeed the gateway. Sorry, I misunderstood the question a bit I see the problem now. You can do a route -n as root(sudo su) and then do route del default gw 192.168.254.1 dev eth0 or, to be more exact, you would use the info from route -n to fill in the del statement, so it's route del default gw <gateway> dev <Iface> – Wilhelm Erasmus Apr 15 '15 at 19:50