How do I configure bonding via sysfs in Red Hat Enterprise Linux 5 and above?
Issue
- How do I configure bonding via sysfs in Red Hat Enterprise Linux 5 and above?
Environment
- Red Hat Enterprise Linux 5
- Red Hat Enterprise Linux 6
- Red Hat Enterprise Linux 7
Resolution
Network bonding can be configured via the sysfs interface. This interface allows dynamic configuration of all bonds in the system without unloading the bonding module. It also allows for adding and removing bonds at runtime. The "ifenslave" comamnd is no longer required, though it is still supported.
Use of the sysfs interface allows you to use multiple bonds with different configurations without having to reload the module.
Creating and Destroying Bonds
To add a new bond bond0:
# echo +bond0 > /sys/class/net/bonding_masters
To remove an existing bond bond1:
# echo -bond1 > /sys/class/net/bonding_masters
To show all existing bonds:
# cat /sys/class/net/bonding_masters
Adding and Removing Slaves
Interfaces may be enslaved to a bond using the file /sys/class/net/<bond>/bonding/slaves. The semantics for this file are the same as for the bonding_masters file.
To enslave interface eth0 to bond bond0:
# ifconfig bond0 up
# echo +eth0 > /sys/class/net/bond0/bonding/slaves
To free slave eth0 from bond bond0:
# echo -eth0 > /sys/class/net/bond0/bonding/slaves
When an interface is enslaved to a bond, symlinks between the two are created in the sysfs filesystem. In this case, you would get /sys/class/net/bond0/slave_eth0 pointing to /sys/class/net/eth0, and /sys/class/net/eth0/master pointing to /sys/class/net/bond0.
Changing and Removing A Primary Slave
To change a primary slave to eth1:
# echo eth1 > /sys/class/net/bonding/primary
To remove a primary slave:
# echo > /sys/class/net/bonding/primary
For more information, see /usr/share/doc/kernel-doc-<version>/Documentation/networking/bonding.txt
Note
You need to have kernel-doc package installed in order to access the above documentation.