Linux Red-hat 6 Network manger interface priority

7,480

Solution 1

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.

Solution 2

Red Hat uses the last interface up as the default gateway device.

To set eth1 as the default, add this to /etc/sysconfig/network:

GATEWAYDEV=eth1

See: https://access.redhat.com/solutions/41459

It should get processed on every ifup call. You can check the routes with ip route show

Share:
7,480

Related videos on Youtube

Kimel
Author by

Kimel

Updated on September 18, 2022

Comments

  • Kimel
    Kimel almost 2 years

    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 !

  • Kimel
    Kimel about 9 years
    Thanks you very much for your detailed answer ! unfortunately I tried this and still eth0 takes priority. the metric and the GATEWAYDEV doesn't seems to effect NM. In the logs I see "Policy set 'eth0' (eth0) as default for IPv4 routing and DNS." any idea what is wrong ?
  • ǝɲǝɲbρɯͽ
    ǝɲǝɲbρɯͽ about 9 years
    bugzilla.gnome.org/show_bug.cgi?id=653789 (not a bug) says to select "Use this connection only for resources on its own network" within NM, the interface, IPv4 settings, routes . If what it means looks right for you (the comments are short) I'll add it and the source to the answer.
  • Kimel
    Kimel about 9 years
    Thanks again, well it is not exactly what I need. if I choose "Use the connection only for resources on it network", there will be no default route on that interface. I need a default route on eth0 when eth1 is unplugged.
  • ǝɲǝɲbρɯͽ
    ǝɲǝɲbρɯͽ about 9 years
    Of course; thanks for the reminder. I have a similar config but can't test failover; in this answer: serverfault.com/a/417404/246220 it is implied that you can swap the gateway interface at that point, using commands like the route changes made here: stackoverflow.com/a/10907667/3981745 . Someone may chime in with a better solution but I can add it anyway.
  • Kimel
    Kimel about 9 years
    Eventually what I did is to remove eth0 from NM NM_CONTROLLED=no and left eth1 controlled. for the eth0 I set the metric to 20 and then I have 2 default routes and the eth1 takes precedence. currently this looks fine for me. Thanks again for your help and effort , I appreciate it very much !
  • ǝɲǝɲbρɯͽ
    ǝɲǝɲbρɯͽ about 9 years
    Okay. I've spent some time in the RedHat scripts and there may be a better answer, combining GMambaG's with how RH utilizes advanced routing. Though two default gateways isn't ideal in the default table, since it's working for you: I'll look at it separately (it comes up in other questions) and link the idea here as an option.