Networking – Prevent Default Route When Bringing Up an Interface

ifconfigipv4networkingrouting

I have a system with two NICs on it. This machine, and a few accompanying devices will be moved and attached to different LANs or sometimes it'll be using dial-up.

    eth0:
    - 10.x.x.x address space
    - no internet gateway
    - only a few devices

eth1 (when used):
- 172.16.x.x or 192.168.x.x or other address spaces
- access to the gateway from LAN to internet

ppp0 (when used):
- internet access through dialup using KPPP

I'm using ifconfig to bring interfaces up or down (other than with ppp0, which is handled by KPPP).

If I bring up eth1 first, it gets an address from its DHCP and gets the gateway and that is added to routing so there's no trouble reaching the LAN and the internet.

If I bring up eth0 first or second, it gets its address and sets the default gateway to within its address space (in the 10.x.x.x range). If I bring up eth0 first and eth1 second, the default gateway is still kept to within the 10.x.x.x range.

So no matter what I do, eth0 will override eth1 and "claim" the gateway in the routing.

Is there some way to either prevent eth0 from claiming the gateway, or to make sure eth1 (if brought up 2nd) uses its gateway? Or can I somehow prioritize a ranking of which interface's gateway should be used over the others?

I basically want to make sure eth1's default address space gateway is used if it's active, and if not, then the ppp0's default gateway is used. I'd like to be able to prevent eth0 from ever having the default gateway.

Best Answer

The DHCP server configuration is wrong. It must not send a default gateway option when it can't provide routing to the rest of the world. If it does send that option then any client may assume that it can send packets for any off-link destination to the specified default gateway.

So your box is right in using the default gateway from eth0 if it is told so by DHCP. The solution is to remove the bad option from your DHCP server.

Related Question