Linux Networking – Change Active Slave of Bonding Interface Without Ifenslave

bondingiproute2linuxlinux-networking

Linux supports bonding of multiple Ethernet network interfaces for extra reliability or load balancing.

Bonding driver used to be configured via ifenslave command, which has been deprecated (superseded by ip command from iproute2 toolkit), so ifenslave was removed from the kernel sources.

One particular feature of deprecated command which I can't find a modern equivalent for is changing an active slave of the bonding interface (assuming that bonding interface is operating in the active-backup mode).

For example, the following commands set eth0 network card as an active slave of bond0 interface:

ifenslave -c bond0 eth0
ifenslave --change-active bond0 eth0

Is there a way to change an active slave of Linux bonding interface using ip command from the iproute2 toolkit or, alternatively, via sysfs?

Best Answer

Create procedure for bonding interface:

# create the bonding interface with active-backup mode
ip link add name bond0 type bond mode active-backup

# add the under laying interfaces
# the interface, that has been added first, will be active
ip link set master bond0 dev eth1
ip link set master bond0 dev eth0

# enable the bonding interface
ip link set up dev bond0
ip address add 192.168.100.1/24 dev bond0

# check the results: detailed info and statistics of bond0
ip -s -s -d link ls dev bond0

# check the state of ALL under laying interfaces
# with statistics and details 
ip -s -s -d link ls master bond0

# check the kernel logs
journalctl -kn 20

To change the active link for bonding device you should use this command:

ip link set dev bond0 type bond active_slave eth0

If you have gotten the error like RTNETLINK answers: invalid argument then check the dmesg or the journalctl -k outputs.

For brief help for options you can use ip link add type bond help command. It applies to any link type.

All values of current options of bond0 interface you can get with ip -d l ls dev bond0 command.