Multiple DHCP uplinks - How to ignore DNS and default route on all but one?

(I am still interested in solutions that only touch /etc/network/interfaces{,.d/}, but not /etc/dhcp/. In the absence of such solutions, I use this one.)

In /etc/dhcp*/dhclient.conf, remove the options routers, domain-name-servers, domain-name, domain-search from the global request statement. Then add this (assuming eth0 is the device where default route and DNS shall not get ignored):

interface "eth0" {
    also request routers, domain-name-servers, domain-name, domain-search;
}

This solution works at least for isc-dhcp-client version 4.2.2.dfsg.1-5+deb70u8 as it is shipped with Debian 7. I assume it works for later versions too.


Edit:

  • Confirmed that the original idea works with minor changes (eth0 must be quoted, and it should be request, not required)
  • Specified the dlclient version this works for

Instead of using inet dhcp you can use inet manual to then specify your own dhclient call to which you can pass a custom dhclient.conf file (note the -cf <file> argument):

iface eth0 inet manual
    up /sbin/dhclient -4 -v -pf /run/dhclient.${IFACE}.pid \
        -lf /var/lib/dhcp/dhclient.${IFACE}.leases -I \
        -df /var/lib/dhcp/dhclient6.${IFACE}.leases \
        -cf /etc/dhcp/dhclient_no_routers.conf ${IFACE}
    down /sbin/dhclient -4 -v -r -pf /run/dhclient.${IFACE}.pid \
        -lf /var/lib/dhcp/dhclient.${IFACE}.leases -I \
        -df /var/lib/dhcp/dhclient6.${IFACE}.leases \
        -cf /etc/dhcp/dhclient_no_routers.conf ${IFACE}

In your custom dhclient.conf (/etc/dhcp/dhclient_no_routers.conf in this case) you can then set your desired DHCP options.

To see what else the inet dhcp method does, see the inet.defn file in the source code (that's where I got some of the dhclient call from above from).