A solution for multiple routes (usb0+eth0)

Helge Hafting helge.hafting at hist.no
Mon Mar 9 10:51:52 CET 2009

Bringing up one interface creates a default route, which is necessary no 
matter which interface is used.

Bringing up both interfaces makes two default routes, and there is the 
risk that the phone ends up using the slower interface which obviously
is a problem.

I set up /etc/network/interfaces like this, adapted from SHR:

auto usb0
iface usb0 inet static
	gateway metric 1
	up echo nameserver >> /etc/resolv.conf
	up echo nameserver >> /etc/resolv.conf

The "metric" does the trick. When usb0 is the only interface, the usb0 
route gets used as usual.

If some other interface comes up (in my case, eth0)
then that one gets a default route too, but that default route
comes up with the default metric of 0.

So, the eth0 default route is seen as "shorter", and is preferred over 
usb0 when both are available. Which is good, as eth0 is faster.

So, no need to delete the usb0 default route when bringing up other 
interfaces, with the associated problem of restoring the usb0 route when 
the other interface goes away.

Helge Hafting

More information about the community mailing list