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?



2 Answers 2


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 dev eth0 proto dhcp src metric 202 
default via dev wlan0 proto dhcp src metric 303 dev eth0 proto dhcp scope link src metric 202 dev wlan0 proto dhcp scope link src 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.


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.

  • 1
    Fiddling with metric doesn't help if an interface fails (e.g. unplugged). This will break all stateful connections (e.g. TCP, ssh, streams, etc.) and you have to reboot to get it again on the other interface. New connections may work without reboot.
    – Ingo
    Sep 22, 2019 at 8:46
  • @Ingo I don't understand the comment. If I disconnect eth0 dhcpcd releases the IP Address and it is removed from the routing table.
    – Milliways
    Sep 23, 2019 at 12:05
  • 1
    You are right. The kernel will to that and it will use the route with the next higher metric. It will also use the new source ip address of the (switched) default route. But this will break all established stateful TCP connections like ssh or others. The other end don't know the new source ip address and get stuck. To avoid this you need an interim interface like bond0 that will not switch its ip address.
    – Ingo
    Sep 23, 2019 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.