Network bonding (wlan & eth) on linux ubuntu

When we moved into our new apartment, we renewed all wires which included proper cat7 in all rooms. So lets take advantage of it... :)

My primary machine is a laptop that I carry around in the house a lot. This breaks open network connections, due to the IP change when NetworkManager switches from the wired interface to the wireless. To not interrupt existing network connections though, it's vital that the machine's IP stays the same regardless of whether it is hooked up with the wired or wireless. This is where network bonding comes into play. It binds both physical devices wlan and eth into a logical one with a single IP address assigned (by remote DHCP). The kernel then takes care of activating the proper device depending on the wired link state (cable connected).

apt-get install ifenslave

me@foo:/etc/NetworkManager $ cat NetworkManager.conf
[main]
plugins=ifupdown,keyfile
dns=dnsmasq
[ifupdown]
managed=false
[keyfile]
unmanaged-devices=mac:00:23:ab:cd:ef:14

"unmanaged-devices" tells NetworkManager to leave the bonding device alone and not interfere with it. It refers to the hw address (mac) of the wifi interface.

me@foo:/etc/network $ cat interfaces
# Bonding for eth0 and wlan0 at home
auto lo
iface lo inet loopback

# Do not receive dhcp on eth0
auto eth0
iface eth0 inet manual
bond-master bond0
bond-primary eth0

# Manually connect wireless to AP
#auto wlan0
iface wlan0 inet manual
wpa-ssid "YOUR_SSID_HERE"
wpa-psk YOUR_WPAKEY_HERE
bond-master bond0

# Request dhcp ip for bonded interface
iface bond0 inet dhcp
bond-mode active-backup
bond-miimon 100
bond-slaves none

Due to issues, wlan0 is brought up via 'ifup wlan0' in /etc/rc.local. Happy bonding (state can be observed via (cat /proc/net/bonding/bond0)

me@foo:/ $ cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

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

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:23:ab:cd:ef:13
Slave queue ID: 0

Slave Interface: wlan0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 00:23:ab:cd:ef:14
Slave queue ID: 0

If one happens to install dropbear on Ubuntu 12.10 with an encrypted disk, network is set to come up as part of initramfs (to remotely unlock the disks). This causes ethX to get an IP address long before bonding has a chance to enslave the device. Removing dropbear and manually running "update-initramfs -u" fixed this issue for me.


Want to comment? Send me an email to blog-comments-2018 at lemmster d.t de and I'll paste it here (I won't publish your address). Why don't you use an external comment service like disqus, you ask? Well, I like to keep this site under my control, comments included. You can use markdown to format your comment.