10

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?

1 Answer 1

10

Short answer

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

Read on for the longer answer and some alternatives. In all cases you have to restart connections to get the change.

Network Manager: ipv4.never-default

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 resources on its network". Its nmcli equivalent is:

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

The first option disables classless static routes, which are not commonly used, while the second disables the default router.

For most people the second option is sufficient. Ponder also setting the first: it might be useful and should not conflict.

Another way: dhclient.conf

In /etc/dhcp/dhclient.conf (but outside of NetworkManager's environment) you can add a stanza for an interface for this DHCP setup:

# Assign this interface an IP address only.
# (This disables setting the gateway router, DNS, domain, etc.)
interface "eth1" {
  request subnet-mask, broadcast-address, interface-mtu;
}

Note that this works by omitting parameters such as rfc3442-classless-static-routes, routers, and a few others.

Yet another answer: ipv4.route-metric

Another method (that I didn't see in the graphical settings) would be increase the metric (thus 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 second 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

One last possibility: use both at once

Yet another 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 multipath routes or routing related firewall rules you can load-balance access and can combine both bandwidths, given enough connections to multiple destinations. But this would be more difficult to integrate correctly with NetworkManager + dhclient.

1
  • I like that this is a thorough answer which covers lots of different answers succinctly. I would, however, suggest that the answer for dhclient.conf is confusing than necessary as it refers to options (such as "routers") which do not help, in my experience. I will edit the answer to put in what does work.
    – hackerb9
    Commented Jan 28, 2023 at 4:28

You must log in to answer this question.

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