Default route in debian with two interfaces

4

1

I have a debian machine with two interfaces, configured by dhcp:

allow-hotplug eth0
iface eth0 inet dhcp

allow-hotplug eth1
iface eth1 inet dhcp

On boot, a default route is added to eth1:

0.0.0.0         10.200.10.253   0.0.0.0         UG    0      0        0 eth1
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
10.200.10.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1

But I need the default route to be a gateway on eth0 instead. Deleting the default route and running dhclient after boot works:

$ sudo route del default
$ sudo dhclient -v eth0

I know I can put this on rc.local, but is there a more "clean" way to do it?

I can't use a static address.

goncalopp

Posted 2014-03-07T11:20:45.673

Reputation: 680

Answers

5

To me, it looks like both DHCP clients spawned -- each for its corresponfing iface -- get the default gateway and race. Things happen this way that the one on eth1 reliably wins (for whatever reason).

The solution does not appear to obvious because it depends on your setup. Getting the default GW using DHCP logically means you do not care about where it is.

Based on this and this, I'd try adding

interface eth1 {
    supersede routers ""
}

to /etc/dhcp/dhclient.conf and see what happens. The idea is to supersede any routers supplied by the DHCP server reached via eth1 with nothing.

kostix

Posted 2014-03-07T11:20:45.673

Reputation: 2 435

Was very useful for me to find this so quickly. Fedora network service uses a different approach and it uses environment variables to drive its own dhclient-script. It is possible to say whether to commit routers per-connection via the DEFROUTE variable in the connection configuration. – Pavel Šimerda – 2014-10-03T21:43:28.340

Thank you, that sent me in the right direction! I guess this wouldn't work if you needed the routes from DHCP (other than the default) - fortunately, I don't – goncalopp – 2014-03-07T13:38:42.370

1Note that the option is routers, not static-routes. I'd say in most setups routers sends just a single host -- the default gateway for the managed network. – kostix – 2014-03-07T15:24:35.087

1@goncalopp, from the manual page -- section on static-routes: "The default route (0.0.0.0) is an illegal destination for a static route. To specify the default route, use the routers option.". (It then goes on to suggest using classless-static-routes instead of static-routes but this has nothing to do with our case.) – kostix – 2014-03-07T15:27:00.707