I would like to route traffic over usb0 (a cellular modem) when it is available instead of eth0. The ip address for usb0 may change over time. How do I create a route in this scenario since the ip address may change?

I tried: ip route add default dev usb0

but when I do this, I am able to ping from usb0 but no longer through eth0. Any thoughts why?

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         UG    10     0        0 eth0  *      U     0      0        0 usb0      *        U     0      0        0 eth0
  • Usually whatever is used to set the variable IP address for the usb0 interface (maybe a DHCP client of some kind?) can provide the default route information too, when requested to do so. If there are other routes already present, you may need to explicitly configure it to add a new default route with a lower metric value than the already-existing one.
    – telcoM
    May 17, 2018 at 6:32
  • udhcpc set the ip but unfortunately it doesn't seem to create a new default route to the internet. It also does not provide the gateway ip address I'm guessing since this is cellular and can change. Is "ip route add default dev usb0 metric 0" the proper way of setting a new default route when gateway ip is not known?
    – Felix
    May 17, 2018 at 13:34

1 Answer 1


In the comments, you mentioned you're using udhcpc as your DHCP client.

udhcpc will pass the gateway address (or addresses, if there are several) to the script it runs (by default, /usr/share/udhcpc/default.script) in a variable named router. This script should then set the default gateway accordingly.

I'm guessing that the default script omits setting the default gateway if there is one already set.

Please see: https://udhcp.busybox.net/README.udhcpc

You cannot just shove packets out any old network interface. If the interface emulates Ethernet, like your usb0 probably does, the package needs a valid Layer-2 destination address. The system can get that automatically by doing an ARP request for the gateway's IP address... but that gateway IP address must be known first.

  • What happens if the cellular modem connects to a different gateway on its own later on , will that cause issues with routing table since it's using the initial gateway ip? Or would it automatically modify the routing table with the new gateway ip? You were right about udhcpc. It wasn't setting the default gateway because eth0 was already the default. I deleted the default before runnin udhcpc and it set it correctly.
    – Felix
    May 17, 2018 at 19:33
  • If your default gateway changes, then your IP address is likely to change at the same time too. It's quite complex at the cellular network side of things, but basically the network should make sure you keep your IP+gateway while you have an active connection... but if you drop out of the cellular network completely, then your IP + gateway address may change. But that should be something that your DHCP client handles automatically after seeing that the network link was lost and then came back again.
    – telcoM
    May 18, 2018 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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