How To Make A Network Interface Come Up Automatically On Link Up?

Home » CentOS » How To Make A Network Interface Come Up Automatically On Link Up?
CentOS 26 Comments

I have a recently installed Mellanox VPI interface in my server. This is an InfiniBand interface, which, through the use of adapters, can also do
10GbE over fiber. I have one of the adapter’s two ports configured for
10GbE in this way, with a point to point link to a Mac workstation with a Myricom 10GbE card.

I’ve configured this interface on the Linux box (eth2) using
/etc/sysconfig/network-scripts/ifcfg-eth2 , setting its IP address, MTU, subnet, etc.

Everything seems to work fine, with a single exception. If I reboot the Mac on the other end, causing the link state of the fiber interface to bounce, the network interface on the Linux box doesn’t come back up when the link comes back up. That is, ifconfig shows it as having the link up, but it doesn’t do the equivalent of “ifup eth2” when the link comes back, so it doesn’t get an IP, the routing table doesn’t get updated, etc.

So, my question is, how can I make CentOS automatically configure this interface when the link comes back up? It’s a bit annoying having to log in and do ifup eth2 every time…

26 thoughts on - How To Make A Network Interface Come Up Automatically On Link Up?

  • what do you find in dmesg and /var/log/messages? The system should bring it up automatically. If not, you should get an error for the prompts.

    ———-

  • I do have ONBOOT=yes, yes. It comes up on boot (if there’s a link), it just doesn’t come up after the link goes down and comes back up.

  • How do I do that? I’ve not used network manager to set it up, I just made the ifcfg-eth2 file from scratch.

  • Besides the other two suggestions you may also want to set a proper SELinux label on the ifcfg-eth2 file with something like:
    /sbin/restorecon -v -F /etc/sysconfig/network-scripts/ifcfg-eth2

    The SELinux label I have on my ifcfg-eth0 is:
    -rw-r–r–. root root system_u:object_r:net_conf_t:s0 ifcfg-eth0

    Regards, Patrick

  • Neither HOTPLUG=yes or MANAGED=no seems to make this interface come back up when the cable is unplugged and then plugged, unfortunately. For instance, before unplugging anything, ifconfig says:

    eth2 Link encap:Ethernet HWaddr 00:02:C9:29:64:8F
    inet addr:10.10.0.1 Bcast:10.10.255.255 Mask:255.255.0.0
    inet6 addr: fe80::2:c900:129:648f/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:9000 Metric:1
    RX packets:47 errors:0 dropped:0 overruns:0 frame:0
    TX packets:26 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:14924 (14.5 KiB) TX bytes:3940 (3.8 KiB)

    Then I unplug the cable, which, in dmesg, gives me:

    mlx4_en: eth2: Link Down

    And in /var/log/messages:

    Mar 25 11:36:24 resolve02 ntpd[4819]: Deleting interface #14 eth2,
    10.10.0.1#123, interface stats: received=0, sent=0, dropped=0, active_time=163 secs

    (Which I guess is just ntpd reacting)

    And then I plug the cable back in, and in dmesg, I have:

    mlx4_en: eth2: Link Up

    Mar 25 11:38:09 resolve02 kernel: mlx4_en: eth2: Link Up Mar 25 11:38:09 resolve02 NetworkManager[4429]: (eth2): carrier now ON (device state 2)
    Mar 25 11:38:09 resolve02 NetworkManager[4429]:
    (eth2): device state change: 2 -> 3 (reason 40)

    But ifconfig gives me:

    eth2 Link encap:Ethernet HWaddr 00:02:C9:29:64:8F
    inet6 addr: fe80::2:c900:129:648f/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:9000 Metric:1
    RX packets:104 errors:0 dropped:0 overruns:0 frame:0
    TX packets:26 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:25567 (24.9 KiB) TX bytes:3940 (3.8 KiB)

    So no IP address, and no joy. ifup eth2 brings me back to:

    eth2 Link encap:Ethernet HWaddr 00:02:C9:29:64:8F
    inet addr:10.10.0.1 Bcast:10.10.255.255 Mask:255.255.0.0
    inet6 addr: fe80::2:c900:129:648f/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:9000 Metric:1
    RX packets:104 errors:0 dropped:0 overruns:0 frame:0
    TX packets:41 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:25567 (24.9 KiB) TX bytes:6493 (6.3 KiB)

    Ideas?

  • Well, /etc/sysconfig/network-scripts/ifcfg-eth2 looks like this:

    DEVICE=eth2
    BOOTPROTO=none ONBOOT=yes NETWORK=10.10.0.0
    NETMASK=255.255.0.0
    IPADDR=10.10.0.1
    USERCTL=no MTU=9000
    HOTPLUG=yes NM_MANAGED=no

  • Hello, I’m just trying to get back to this, since no one has answered my questions… Is this really a very difficult thing to accomplish?

  • I’ve tried various combinations of HOTPLUG=yes and no, and MANAGED=yes and no, then someone asked me if this was really not managed, so I
    posted the dmesg output above.

  • Do I need to disable NetworkManager for everything to make this work?

    As I’d mentioned before, the problem isn’t that the interface doesn’t come up on boot, it does, but since it’s a point to point interface, when I reboot the computer on the other end, it goes down and doesn’t come back up automatically. That is, link going down and up makes the network configuration stay down, I have to manually take the interface down and back up to make it work again.

  • Joakim Ziegler wrote:

    Disabling NetworkManager, if you’ve got a wired connection, is *always* a Good Idea, IMO. There’s *no* reason for it on anything but a mobile system.

    Now – did you say that this was an infiniband connection? We’ve got one system like that, and it’s ip0. The ifcfg-ib0 we’ve got is
    DEVICE=ib0
    TYPE=Infiniband
    BOOTPROTO=static
    BROADCAST2.168.20.255
    IPADDR2.168.20.1
    NETMASK%5.255.255.0
    NETWORK2.168.20.0
    ONBOOT=yes

    mark

  • It’s not an InfiniBand connection per se. It’s a Mellanox VPI card, which has IB ports that can be configured to be 10GbE, through an adapter and fiber transciever. I’ve currently got one of its two ports set up to be 10GbE, and it shows up as eth2. The other port on the card, which is configured as IB, is indeed ib0, but that’s not the one causing me problems.

    I will try to completely disable NetworkManager per the instructions, and see if that works. Thanks.

  • From: Joakim Ziegler

    Not the solution you want but, as a last resort, you could always have a cron script that checks every minute if the link is down…

    JD

  • Or consider putting “* * * * * /sbin/ifup eth2” in root’s crontab. If eth2 is up, it simply rereads the configs (which haven’t changed). If it was down, it brings it up.

    c

  • This seems really dirty. :)

    Also, I actually have to take it down and back up to make it work currently. But I will try the recipe I got soon and see if that fixes it.

  • You can create these two files which will be executed every time interface comes up & goes down.

    /sbin/ifup-local
    /sbin/ifdown-local

    mark them as executable.

    The Device name will be passed as argument.

    example, /sbin/ifup-local eth0.

    use case or if statements for interface parsing in the script.

  • I’m pretty sure HOTPLUG is only used when the interface ITSELF is attached to the system at runtime, not the cable, and MANAGED isn’t used at all.

    If you set NM_CONTROLLED=no then the configuration will be loaded only if the system starts the “network” service and the configuration will not change on link up/link down.

    Otherwise, you need to check the messages log file for information from NetworkManager. dmesg will not tell you what you need to know.

LEAVE A COMMENT