Pi os wifi and eth0 no internet

I’m using my pi to access my home lab network via the pi’s wired ethernet and using the pi’s wifi to connect the pi to the home wifi. The pi is using raspian bookworm.

When I shutdown the homelab to save $ I loose the ethernet. As expected but what is not expected is that the pi looses dns resolution and I have to specify which nic to use even though the home wifi is up and running.

I’m assuming that everything is defaulting to eth0. Thus if I take down the lab network then the pi cannot connect to the dns nor acces the internet. But I do this all the time on my laptop. I disconnect it from the wired connection and just use the wifi or have both connected at the same time.

So how do I fix this?

> ip route
default via 192.168.40.1 dev eth0 proto static metric 100 
default via 192.168.35.1 dev wlan0 proto static metric 600 
192.168.35.0/24 dev wlan0 proto kernel scope link src 192.168.35.50 metric 600 
192.168.40.0/24 dev eth0 proto kernel scope link src 192.168.40.50 metric 100
> nmcli device status
eth0        ethernet  connected               Wired connection 1         
lo          loopback  connected (externally)  lo                 
wlan0       wifi      connected              WiFi

When the home lab network is turned on everything works.

When the home lab is turned off. Things break on the pi.

ping 9.9.9.9 - does not work
ping -I wlan0 9.9.9.9 works

ping google.com - does not work
ping -I wlan0 google.com - does not work

ping 172.217.25.174 - does not work - this is google.com
ping -I wlan0 172.217.25.174 - does work

I assume that 192.168.40.1/24 is the home lab network, the other one the home wifi network.

The rpi will send all packets not directly connected to local nets to 192.168.40.1 (the default route with lowest metric (100)).
Once, that network is powered off, all those packets disappear without feedback :frowning:
That explains why your rpi cannot even resolve names when the home lab network is down.

Multiple ways to “fix” this:

  1. lower the cost to access the wifi network, as a result all your traffic not connected to local networks will travel over wifi.
Following lists all available connections. I assume one to be called $con-wifi and one to be called $con-lab - replace in following commands accordingly
~# nmcli con
Assign specific priorities to each connection. To revert, assign default value of -1.
~# nmcli con mod $con-wifi ipv4.route-metric 50
~# nmcli con mod $con-lab ipv4.route-metric 100
restart connections to pickup config changes.
~# nmcli con down $con-wifi 
~# nmcli con up $con-wifi 
~# nmcli con down $con-lab
~# nmcli con up $con-lab
  1. remove the “gateway” from your cabled (home lab) connection. This will remove the first line from your “ip route” command output.
~# nmcli con mod $con-lab ipv4.gateway ""
Restart connection
~# nmcli con down $con-lab
~# nmcli con up $con-lab

2 Likes

Thanks Jode, it worked. I set the wifi metric value to 50 and the rpi is now favoring the wifi and not eth0. And the pi now has access to dns and the pi is acting normally.

1 Like

I’m hoping that this helps others running across the same or similar situation.

I was getting confused as to why my pi was not routing access to the internet when it was connected to the home wifi and when the lab network was down. I was doing the same thing with my laptop.

I would connect the laptops ethernet to the lab network and home wifi and everything would work fine. I would disconnect the ethernet connection to the lab network and the laptop would still have access to the internet through the wifi. So whats the diff?

I think I understand it now. When the laptop’s ethernet is unplugged, the networkmanager is rewritting the ip routes table because the ethernet knows its disconnected.

On the rpi’s case the ethernet is connected to the switch and has an electrical connection and its on a static ip address. so no its not pulling a dhcp address and network manager is not rewritting the ip routes table with the updated info that the ethernet is down.

Thanks Jode for the help and here is more info from ubuntu if anyone else needs help:
https://ubuntu.com/core/docs/networkmanager/networkmanager-and-netplan

2 Likes