Here is an issue I have stumbled uppon a couple of times and for which I still have no solution.
I have a NetworkManager managed box with two interfaces. Let's call them eth0 and eth1.
Both NEED to get ip over dhcp, and they both add their default gateway. What I would like is to have one of them not applying the default gw.

In the last iteration of this situation I learned that NetworkManager creates a /var/lib/NetworkManager/dhclient-eth0.conf from /etc/dhcp/dhclient.conf.

Is this a missing feature of NetworkManager or I should try to create a new dhclient.conf that contains dhcp request information for each iface with different request sections?


There's such a feature in NetworkManager. If you want to limit eth1 which is for example called My eth1 connection , graphically it's accessible with Edit Connections > My eth1 connection > IPV4 Settings > Routes

There are two toggles:

  • "Ignore automatically obtained routes". Its nmcli equivalent:

    nmcli connection modify id 'My eth1 connection' ipv4.ignore-auto-routes yes
  • "Use this connection only for ressources on its network". Its nmcli equivalent is:

    nmcli connection modify id 'My eth1 connection' ipv4.never-default yes

The second option should do what you want.

I suspect the first option is disabling additionnal routes received with Classless static route option which isn't very used in common DHCP settings, while the second is disabling the default route from Router option. So for most cases, that's the second option you should use (and that works for me).

In dhclient.conf (but outside of NetworkManager's environment) the options would be rfc3442-classless-static-routes and routers.

An other method (that I dodn't see in the graphical settings) would be increase the metric (this lowering "priority") of a connection. By default it's automatic and it seems wifi has a higher metric than ethernet for example. With this you can have both default routes, but the 2nd route isn't used until the first disappears. From this description, to give priority to "My eth0 connection" over "My eth1 connection" that would be:

nmcli connection modify id 'My eth0 connection' ipv4.route-metric 100
nmcli connection modify id 'My eth1 connection' ipv4.route-metric 500

In all cases you have to restart connections to get the change.

Yet an other method to get your two DHCP connections fully working at the same time would be to setup routing for multiple uplinks/providers. With this and a few iptables rules you can load-balance access and can combine both bandwidths, given enough connections to multiple destinations. But good luck for integrating this into NetworkManager + dhclient.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.