4

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.

1 Answer 1

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.

4
  • 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 Commented Mar 7, 2014 at 13:38
  • 1
    Note 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
    Commented Mar 7, 2014 at 15:24
  • 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
    Commented Mar 7, 2014 at 15:27
  • 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. Commented Oct 3, 2014 at 21:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .