Howto: active-backup bonding

This short tutorial describes how to create an active-backup bonding with netcfg, wpa_supplicant, systemd, ..

packages

I had to install (additionally) ifplugd and ifenslave

bonding config

The config file /etc/modprobe.d/bonding.conf needs to be adapted to:

/etc/modprobe.d/bonding.conf:

options bonding mode=active-backup
options bonding miimon=100
options bonding primary=eth0
options bonding max_bonds=0

wpa_supplicant

First create a wpa_supplicant config file with all you wireless networks, passwords and stuff in it - here it is: /etc/wpa_supplicant/wpa_supplicant-roaming.conf (example file should be available in the directory)

You can run wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-roaming.conf -iwlan0 to test if it works so far. It should connect to one of the available wireless networks (but without getting an ip address). Run dhcpcd wlan0 to get an ip and check if your wpa_supplicant config works so far.

If it works we have to enable it automatically at startup. This is done by creating /etc/systemd/system/mywpa_supplicant@.service with the following content:

/etc/systemd/system/mywpa_supplicant@.service:

[Unit]
Description=Provides wireless connectivity via wpa_supplicant

[Service]
ExecStart=/usr/sbin/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-roaming.conf -i%i

[Install]
WantedBy=multi-user.target

Then enable it with systemctl enable mywpa_supplicant@wlan0 and maybe try starting it manually by systemctl start mywpa_supplicant@wlan0.

netcfg profile

Create a profile like /etc/network.d/bond with the following options:

/etc/network.d/bond:

CONNECTION='bond'
DESCRIPTION='bonding device'
INTERFACE='bond0'
SLAVE_INTERFACES=('eth0' 'wlan0')
IP='no'
SKIPNOCARRIER='no'

Enable it at startup via systemctl enable netcfg@bond.service

ifplugd

This is required to recognize the plug-in and plug-out of the ethernet. It restarts the dhcpcd for the correct device.

Create file /etc/ifplugd/bond_dhcp.action and make it executable by chmod +x /etc/ifplugd/bond_dhcp.action

/etc/ifplugd/bond_dhcp.action:

#!/bin/sh

case "$2" in
  up)
    systemctl start "dhcpcd@$1.service" && exit 0
    ;;
  down)
    systemctl stop "dhcpcd@$1.service" && exit 0
    ;;
  *)
    echo "Wrong arguments" > /dev/stderr
    ;;
esac
exit 1

Now create the systemd service which starts ifplugd for bond0:

/etc/systemd/system/net-auto-bonded@.service:

[Unit]
Description=Provides automatic dhcp resolution for bonded failover connection
Requires=netctl@bond.service
After=netctl@bond.service

[Service]
ExecStart=/usr/bin/ifplugd -i %i -r /etc/ifplugd/bond_dhcp.action -fIns

[Install]
WantedBy=multi-user.target

And enable it via systemctl enable net-auto-bonded@bond0.service

Reboot and enjoy!

Used sources: