Home Blog Simulation Papers

How to set up network interface bonding with netctl / Archlinux

2021-03-06

Bonding is a useful type of Linux network interface that allows two or more network interfaces to be used for the same LAN. One use case is when a wired and wireless connection are both used and the wired connection should be preferred if the Ethernet cable is connected. Bonding allows seamless switching between using the wired and wireless connection as the cable is plugged and unplugged.

Below are the netctl configuration files I use. The bond mode should be set to active-backup. Note that the IP configuration is set in the bond configuration file, and not in the individual interface configurations. There is no configuration file for the ethernet interface because all that's needed to be done is for the interface to be brought up. netctl will bring up all interfaces listed in BindsToInterfaces when the bond configuration is started.

Be sure to change the interface names eth0 and wlan0 to match yours, and set the IP and wireless security settings appropriately.

/etc/netctl/bond:

Description='Ethernet primary with wifi backup'
Interface=bond0
Connection=bond
BindsToInterfaces=(eth0 wlan0)
IP=static
IP6=no
Address='192.168.0.XXX/24'
Gateway='192.168.0.1'
DNS='192.168.0.1'
Mode=active-backup
LinkOptions='miimon 100 primary eth0 updelay 100 downdelay 100'

primary eth0 indicates that the eth0 interface should be used if both are connected, while miimon, updelay, and downdelay specify the time in milliseconds to wait before checking for link connectivity and switching between interfaces.

/etc/netctl/wifi_bond:

Description='Wifi for bonding: no IP'
Interface=wlan0
Connection=wireless
Security=wpa
ForceConnect=yes
IP=no
IP6=no
ESSID='WIFI_SSID'
Key=XXXXXXXXXX

ForceConnect=yes ensures the wifi configuration will not fail to start if the bond configuration has already brought it up.

To use this configuration, run

# netctl start bond && netctl start wifi_bond

It's very important that the bond configuration is started before the wifi configuration, since an interface cannot be enslaved if it is "UP". If the wifi configuration is started first, the bond configuration will silently fail to enslave it and the wifi interface will not be used in the bond. A more sophisticated network manager than netctl can likely provide a better way to handle this.

For a thorough read on bonding, and an explanation of all options, see https://www.kernel.org/doc/Documentation/networking/bonding.txt.

Useful guides on bonding for other network managers:

Happy bonding!