Gateway settings for multiple network connections

I know this is more of a LINUX question and I have searched the LINUX boards, but I think people here can give me a more clearer answer than what I have found.

I have multiple Pi's 3B+s each running Octoprint 1.3.9 and Octopi 0.15.1. Each Pi's ethernet port (eth0) is connected to a private network with DHCP but no DNS. Each Pi is also wirelessly connected to a WiFi network (wlan0) with browser authentication (like a hotel). The internet connection with just the WiFI (ethernet not connected) works great but when the ethernet port is connected the Pi can no longer access the internet. I am sure this is because the Pi is defaulting to the eth0 port for the gateway. With no ethernet connection the Pi is setting the default gateway to wlan0.

So I am pretty certain all I need to do is establish the wlan0 port as the default gateway even when eth0 is active. The wlan0 connection needs to be DHCP and I would prefer the eth0 port also be DHCP (although I could change eth0 if absolutely needed).

My etc/network/interface file on the Pi reads as follows:

source-directory /etc/network/interfaces.d

The etc/network/interfaces.d folder is empty. I am comfortable accessing the Pi via PUTTY or WinSCP. I am pretty sure there is just some gateway setting I need to establish but I have not been able to find it.

All of this is important because the eth0 port is how I SSH/connect into the Pis and I would like to use the wlan0 port to allow the Pi (and Octopi) to be able to access the internet for updates etc. Complicated I know, but it almost completely works.

As of the last major Raspbian release (Stretch, I think), it's not using those files. It uses the wpa_supplicant service. The area that you want to be playing around in is /etc/wpa_supplicant/wpa_supplicant.conf instead and to the best of my knowledge, even for eth0 which you wouldn't expect.

route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.20.30.1      0.0.0.0         UG    303    0        0 wlan0
10.20.30.0      0.0.0.0         255.255.255.0   U     303    0        0 wlan0

Before you continue, review your routing table. The default route which contains the "G" flag is where things go by default (the Internet). Having successfully changed your setup, that G should move over to your wi-fi adapter's interface.

So edit that file I mentioned and the wi-fi paragraph (only) gets a gateway 192.168.1.1 or whatever assigned to it. Reboot and run that route command again to confirm.

@OutsourcedGuru, thank you very much for your continued help. I think I am close but still cannot quite find the problem and I understand if we give up. I looked at everything you mention and also just poked around in other areas looking for gateway settings. I have 3 different setups but all are similar. Here is what I have.

My route looks like this (with header info included and stockdale being my hostname rather than octopi):

Access OctoPrint from a web browser on your network by navigating to any of:

    http://stockdale.local
    http://20.20.20.200
    http://172.21.202.72

https is also available, with a self-signed certificate.
------------------------------------------------------------------------------
OctoPrint version : 1.3.9
OctoPi version    : 0.15.1
------------------------------------------------------------------------------

pi@stockdale:~ $ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         20.20.20.100    0.0.0.0         UG    202    0        0 eth0
default         172.21.200.1    0.0.0.0         UG    303    0        0 wlan0
20.20.20.0      0.0.0.0         255.255.255.0   U     202    0        0 eth0
172.21.200.0    0.0.0.0         255.255.252.0   U     303    0        0 wlan0

My wpa_supplicant.conf file is:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
	ssid="GNBA-G"
	key_mgmt=NONE
}

Both of these make sense to me. GNBA-G is the SSID of my WiFi network with internet access. This is the 172.21.200.1 internet gateway (equivalent to your 192.168.1.1 example) and is assigning this Pi 172.21.202.27 via DHCP (and I cannot change). GNBA-G has no password but uses a browser authentication which I can do using chromium from the Pi desktop interface. Other Pis have other entries for every SSID I have ever connected to (like my phone and home WiFi) but the wpa_supplicant files never have any eth0 info.

The route list also make sense but by my read shows both as "G" being gateways. The 20.20.20.100 address is the router on my private printing network (very long story). I access the Pis and essentially do everything on this 20.20.20.xxx network. That router is set to DHCP wireless connections to the range of 20.20.20.200 to 20.20.20.255 (I have several statics below that range for ethernet based 3D printers).

So the problem still appears to be that the Pi sees 2 gateways but wants to default to the eth0 one. When eth0 is unplugged the wlan0 becomes the gateway and works - but then I lose my normal connection to the Pi. Complicated I know.

On a separate note, I appreciate your help on my other thread and I have made a ton of progress on that side. I have 2 different mini-KVM-setups (one touch and one not) and they both work great. I have also setup TouchUI which I find helpful but I am waiting on user feedback to see which we will go with. My last (hopefully) step will be to try and setup a remote desktop connection (from the 20.20.20.xxx network) so I can remotely do all of this in a desktop GUI. I am looking at XRDP, X11, and XTERM as possible ways. Over my head as usual and if I cannot get over this last hurdle, I will give up and just go with what I got. The vast majority of this is way over my student users ability (and desire).

You've got two default routes. That would be why you're having difficulties. One of them (eth0) has to go. To fix it, I think you need to (now) edit the /etc/dhcpcd.conf file. You need to remove the gateway line that's associated with the eth0 adapter.

If you know the particular route command that would work at the command line, there's a way of hooking into this, creating a file like...

/lib/dhcpcd/dhcpcd-hooks/40-ethroute

...which contains something like...

ip route remove 20.20.20.0/24 via 20.20.20.100

At least now you'd know what a proper routing table would look like. It will have that first "default..." line missing.

1 Like

This!

When you are running multiple network interfaces, it is important to only have a gateway address set up for ONE of those interfaces, otherwise the computer will not know which interface to use when a packet originates that is not on its internal network. It will just try to send it to any gateway that will respond. I assume the 20.20.20.100 gateway for the eth0 interface is not internet enabled.

As a side note, you should consider changing the 20.20.20.0/24 network to something that falls within the standard Private IP ranges IAW IETF RFC 1918. 20.20.20.0/24 is a routeable Public IP network address. As this is a /24 network you can use any class address so you have a ton of options in the Private IP space to work with. 10.20.20.0/24, 192.168.20.0/24, 172.20.20.0/24 - just to cite a few examples.

Certainly not saying it won't work the way you have it, it's just bad practice to use public IP addresses on a private LAN.

1 Like

@OutsourcedGuru and @davidmarshall3, thanks for the help. I did change my /etc/dhcpcd.conf file by essentially shifting the eth0 port to static and then after reboot, only the wlan0 came up as a default gateway. This works fine so now the Pis have access to the private network on eth0 and the internet through wlan0 which is exactly what I wanted. I can now use the update functions of octoprint as well as a host of other internet functions. Still a couple bumps (the Pis do not show up in my router table the saw way they used to and the uPnP functionality does not work perfectly) but I can get around these. Here is the code I used:

interface eth0
static ip_address=20.20.20.199/24

then reboot (I shifted to .199 from .200 to stay away from my routers DHCP of .200 to .255.

------------------------------------------------------------------------------
Access OctoPrint from a web browser on your network by navigating to any of:

    http://stockdale.local
    http://20.20.20.199
    http://172.21.202.72

https is also available, with a self-signed certificate.
------------------------------------------------------------------------------
OctoPrint version : 1.3.9
OctoPi version    : 0.15.1
------------------------------------------------------------------------------

pi@stockdale:~ $ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         172.21.200.1    0.0.0.0         UG    303    0        0 wlan0
20.20.20.0      0.0.0.0         255.255.255.0   U     202    0        0 eth0
172.21.200.0    0.0.0.0         255.255.252.0   U     303    0        0 wlan0
pi@stockdale:~ $

@davidmarshall3, I also appreciate your comments on public vs private networks, but that opens up an entirely new can of worms that I have been fighting for years. The quick story is the 20.20.20.xxx network originated from a vendor installed piece of lab equipment and I have essentially built several labs around that framework. We have many many laboratory devices with ethernet connectivity that are not as easily configurable as a PC. I have not had a problem on this 20.20.20.xxx network and the one time someone else tried to make it one of the private networks 10.xx.xx.xxx we had an enormous IP conflict that almost brought down my entire lab (we conflicted with my university network and my IT Department saw unusual activity across the domains and went crazy). Anyway, it works and at this point is too hard to change so I am going to stick with it until forced to change.

1 Like