Sunday 23 September 2018

Fedora: bonding over ethernet and wifi devices finally works

Bonding network interfaces for a laptop is a useful feature allowing you to keep the same IP as you switch between a ethernet or wifi connection. However when I last tried this with Fedora26/network manager 1.8 this wasn't a s success.


With the Fedora 28 release with network manager 1.10.10, it is now possibe to create a bond over an ethernet and wifi device

The steps to creating our bond is a simple process:
  • determine the ethernet and wifi devices we want to bond
  • create bond
  • create and add wifi and ethernet slaves to the bond
The slight complication is that the network connection manager gui does NOT allow you to create wifi bond slaves but this is available via nmcli

Determine devices

These device names may be different on your machines
$ nmcli d
DEVICE TYPE STATE CONNECTION
wlo1 wifi connected --
enp1s0 ethernet unavailable --
lo loopback unmanaged --

$ nmcli c show
NAME UUID TYPE DEVICE
mywifinet c9c65851-15fe-424f-8446-c36c48ff3b68 wifi --
enp1s0 1233c772-2ce4-4b49-904c-d75672037462 ethernet --
ethdhcp 443e4605-93f3-4334-9fc0-dd99933669c1 ethernet --

Create the bond

The bond should use the ethernet device whereever possible but if it becomes unavailable use the wifi device (ie we've unplugged the ethernet cable) and swing back to ethernet as soon as it's back. These options MUST be specified at the creation time - modifying the bond connection afterwards did not work for me. At this point we also specify the IP address/gateway/DNS for this bond interface.
$ nmcli con del bond-eth bond-wlan bond

$ nmcli con add type bond con-name bond \
ifname bond0 mode active-backup primary enp1s0 +bond.options "fail_over_mac=active,miimon=100,primary_reselect=always,updelay=200" \
ip4 192.168.0.123/24 gw4 192.168.0.1 ipv4.dns "8.8.4.4 8.8.8.8" \
ipv4.method manual \
ipv6.method ignore

Create the slaves

Create the slaves and attach them to the bond. Notice the wifi slave creation uses the add type wifi ... slave-type syntax.
$ nmcli con add type wifi con-name bond-wlan \
slave-type bond master bond0 ifname wlo1 ssid mywifinet
$ nmcli con add type ethernet con-name bond-eth \
slave-type bond master bond0 ifname enp1s0
And set the password for the wifi slave device via nm-connection-editor or:
$ nmcli con modify bond-wlan wifi-sec.key-mgmt wpa-psk
$ nmcli con modify bond-wlan wifi-sec.psk password

Tidy up and start

At this point we're able to bring up the bond device but first we should bring down the existing wifi/ethernet devices and stop them from auto-connecting - this makes sure theres nothing conflicting with the bond device we've just created
$ for i in mywifinet enp1s0; do
nmcli c down $i \
nmcli c modify $i autoconnect no \
done
$ nmcli c up bond
With no ethernet cable attached we can still hit the network via ping - we can confirm what the kernel knows:
$ cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: None
Currently Active Slave: wlo1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 200
Down Delay (ms): 0

Slave Interface: wlo1
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: ......
Slave queue ID: 0

As soon as the ethernet device is connected we observe a small delay in switching over but no disruption and we can see the kernel now sees the ethernet device as primary / selected device for network comms.
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: enp1s0 (primary_reselect always)
Currently Active Slave: enp1s0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 200
Down Delay (ms): 0

Slave Interface: wlo1
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: ...
Slave queue ID: 0

Slave Interface: enp1s0
MII Status: up
Speed: 100 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: ...
Slave queue ID: 0

and network manager confirms the devices are there:

$ nmcli c show
NAME UUID TYPE DEVICE
bond 9857b8e1-4a95-46d1-a1ff-8353f19e431d bond bond0
bond-eth 6ddb00c5-7d4b-4de7-a193-3a05b0dd005c ethernet enp1s0
bond-wlan 2f47fa03-ac03-4020-8947-07e0cd4c9f80 wifi wlo1

No comments:

Post a Comment