I have a RaspberryPi Zero with WIFI, that is connected to a USB modem (emulating ethernet, which produces eth0). Both work. I want to be able to select which one to use, and which one to be fallback. What is the correct way of doing this?
Thanks!
I have a RaspberryPi Zero with WIFI, that is connected to a USB modem (emulating ethernet, which produces eth0). Both work. I want to be able to select which one to use, and which one to be fallback. What is the correct way of doing this?
Thanks!
This is a typical use case for dynamic failover. This will configure both interfaces eth0 and wlan0 and use one primary interface that you can define. if this connection fails it will automatically use the other interface as fallback. How to setup this you can look at Howto migrate from networking to systemd-networkd with dynamic failover.
Preferred routing is determined by the metric. Lower metrics are preferred.
This can be shown by ip r
e.g.
default via 10.1.2.1 dev eth0 proto dhcp src 10.1.2.74 metric 202
default via 10.1.2.1 dev wlan0 proto dhcp src 10.1.2.84 metric 303
10.1.2.0/24 dev eth0 proto dhcp scope link src 10.1.2.74 metric 202
10.1.2.0/24 dev wlan0 proto dhcp scope link src 10.1.2.84 metric 303
dhcpcd
sets these by default, assigning a higher priority to Ethernet (which is usually desirable), but you can change this by setting the metric
for an interface in dhcpcd.conf
.
metric
Metrics are used to prefer an interface over another one, lowest wins.
dhcpcd will supply a default metric of 200 + if_nametoindex(3).
An extra 100 will be added for wireless interfaces.
eth0
dhcpcd
releases the IP Address and it is removed from the routing table.
– Milliways
Sep 23 '19 at 12:05