Linux Red-hat 6 Network manger interface priority

linuxlinux-networkingrouting

I have a question regarding RedHat 6 Enterprise Network Manager (NM):

My Linux is connected to two network interfaces.

1 – eth0: Normal Ethernet which is connected to the company LAN

2 – eth1: An USB dongle which is connected to a cellular network (CDC-ECM)

eth0 interface is always connected and eth1 interface is non-permanent (the connection can come and go)

When both connected, NM gives priority to eth0. Meaning, the default route (0.0.0.0) is always defined through it.

I want to change the NM policy that it will give higher priority to eth1. When the eth1 interface is not connected the default route should defined through eth0 interface and when eth1 is connected the default route should go through eth1.

I searched the net on how to do it and played with the NM scripts and ifcfg-eth0 / ifcfg-eth1 files (tried DEFROUTE and other options) but couldn’t make it work.

Can anyone suggest what should be the right way to do it using NM ?

Thanks !

Best Answer

Edit: Add OP's solution from comments:

  • Remove eth0 (wired) from NM
    • NM_CONTROLLED=no
  • Left eth1 (wireless) controlled.
    • The default when NM_CONTROLLED is omitted
  • Set eth1 METRIC=20
  • Produces 2 default routes where eth1 takes precedence

Answer:

Network Manager may always choose wireless or wired as primary (based on other questions here) which seems to include interactions with the route's metric and dhcp, router advertisements (where NM followed a 1 metric), interface up/down and RedHat-specifics.

Assuming you're using it: DHCP may reset your route to the "better" one according to its route metric¹. Higher metric values are more "expensive" so the less costly metrics are preferred. In the Network Manager list here, it's noted that dhcp wireless metrics are penalized +100, and the NM developers say NM should just choose the right route, but also that metrics may be the best device method. I'm not sure this applies to your eth1, but you can control it:

Swapping the numbers (10 and 20) from this answer for your interfaces, I get:

$ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
METRIC=20

$ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth1
METRIC=10

That answer says this should prefer wireless and perform a graceful failover between interfaces.

If you want NM to select as the dev's may intend, GMambaG's interface keywords are also considered in the RedHat docs for static routes, which note unexpected problems using multiple gateways + GATEWAYDEV. To test that, start both interfaces and try to resume operations after removing eth1. If you have trouble (like intermittent timeouts), you should be able to recover by removing your changes and restarting networking:

$ sudo service network restart

If all else fails, router advertisements (ICMP types 9 and 10 I think) may be affecting your route tables; coordinate with the network admin before trying to block them.

Edit: Reduced this answer's text, placed OP's solution on top.

¹ If you're not using DHCP you'd have a manual gateway. This article suggests using NM_CONTROLLED="no" to prevent NM from automatically switching to that interface's gateway.