Ubuntu: ethX Interface not bonded after unplugging and plugging its cable back

I am trying to set up fail-back configuration in bonding but I am unable to get around the interface configuration. My interface is as follow:

auto bond0
iface bond0 inet static
       address 192.168.1.39
       netmask 255.255.255.0
       up /sbin/ifenslave bond0 eth1 eth3
       down /sbin/ifenslave -d bond0 eth1 eth3

My /etc/modprobe.d/bonding.conf file is:

alias bond0 bonding
options bonding mode=3

I test it by running ping from other system. My bond status is as follows:

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (broadcast)
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 44:a8:42:03:68:2c
Slave queue ID: 0

Slave Interface: eth3
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 44:a8:42:03:68:2c
Slave queue ID: 0

When I remove eth1 cable the fail-over works and eth3 carries out the data (The ping still continues).

If I connect back eth1 and remove eth3 the ping stops and the bonding status doesn't contain any of the interface. The bond status is:

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (broadcast)
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0

I tried with all the modes in the bonding ( 0 to 6 ). But none of the configuration provides the fail-back support. Where am I going wrong?


EDIT 2019-01-10: These instructions are for Ubuntu 16.04 and older. I will try to update with instructions for 18.04.

In this answer, we are using active-backup bonding with a bond-primary interface set that allows for fail-over to go back to the primary when it is available. More information can be found: https://wiki.linuxfoundation.org/networking/bonding


Bonding in Ubuntu is a different setup then as in other distros of Linux like RedHat. I have done a few bonding configurations in Ubuntu and I will lay it out below as best as possible.

As it looks, you already have ifenslave installed, but if not, install ifenslave:

sudo apt-get install ifenslave

Next, take a look at /etc/modules and make sure it has the following lines:

loop
lp
rtc
bonding

In the /etc/network/interfaces file, set your loopback, eth1, and eth3 interfaces:

auto lo
    iface lo inet loopback

auto eth1
    iface eth1 inet manual
    bond-master bond0
    bond-primary eth1

auto eth3
    iface eth3 inet manual
    bond-master bond0

Now set your bond0 interface with active-backup for fail-over if one of the NIC connections fail:

auto bond0
    iface bond0 inet static
    address 192.168.1.39
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.1
    bond-mode active-backup
    bond-miimon 100
    bond-slaves none

Save the changes to /etc/network/interfaces file and restart your networking service:

sudo /etc/init.d/networking restart

Now you can check your bonding setup. Make sure that your bond0, eth1 and eth3 are correct:

sudo ethtool bond0
sudo ethtool eth1
sudo ethtool eth3

Check to see if fail-over now works by removing eth1 from bond0:

sudo ifenslave -d bond0 eth1

Check to see if you can still ping the gateway:

ping -c2 192.168.1.1

Add eth1 back to bond0:

sudo ifenslave bond0 eth1

Hope this helps!