Channel Bonding to share the same IP for Wired & Wireless interfaces

Unlike when using NetworkManager or Wicd this setup allows uninterrupted switching between wired and wireless, no connections will be interrupted in the switch.

As of this writing (Summer 2012) neither NetworkManager nor Wicd handle this kind of setup.

Required: ifenslave

Create bond0, enslave lan and wifi interfaces. (Nowadays usually optional) Tell wpa_supplicant packets enter through bond0.



# modprobe -v bonding
# ifenslave bond0 wlan1
# ifconfig wlan1 up
# ifconfig bond0 up
# wpa_supplicant -B -c /etc/wpa_supplicant.conf -i wlan1 -b bond0 
# ifenslave bond0 eth1
# ifconfig eth1 up
# echo eth1 > /sys/class/net/bond0/bonding/primary
# dhclient -v bond0


# dhclient -v -r bond0
# ifconfig bond0 down
# ifconfig eth1 down
# ifconfig wlan1 down
# killall wpa_supplicant    # Is there a "clean" way?
# ifenslave -d bond0 eth1
# ifenslave -d bond0 wlan1
# modprobe -v -r bonding


In Debian this can be achieved directly through /etc/network/interfaces:

allow-hotplug bond0 # or "auto bond0"
iface bond0 inet dhcp
	bond-primary eth1
	bond-slaves eth1 wlan1
	bond-mode active-backup    # or bond-mode 1
	bond-miimon 150

allow-bond0 wlan1
#allow-hotplug wlan1
iface wlan1 inet manual
        bond-master bond0
        bond-primary eth1
        bond-mode active-backup
        bond-miimon 150
        # Usually optional: set wlan1 as active temporarily, tell wpa_supplicant to use bond0
	#bond-give-a-chance 10
	#wpa-bridge bond0
	# Single Wireless location/access point:
        #wpa-ssid "#MY SSID#"
	#wpa-psk #MY KEY#
        # Multiple wireless locations
        wpa-roam /etc/wpa_supplicant/wpa-roam.conf   # And set-up wpa-roam.conf with SSIDs and Keys

allow-bond0 eth1
#allow-hotplug eth1
iface eth1 inet manual
        bond-master bond0
        bond-primary eth1
        bond-miimon 150
        bond-mode active-backup
  • bond0 will use the master MAC
  • allow-bond0 will bring wlan1 and eth1 up when bond0 gets up
  • Bringing up one of the slaves interfaces will bring up bond0 BUT not the other slaves
  • wpa-psk can be set to a hashed value, obtained with $ wpa_passphrase <SSID> <actual passphrase>

Enable with # ifup bond0. Release a enslaved interface with # ifdown interface.

With cable connected, eth1 is used. Without, wlan1 is used.
See status with $ cat /proc/net/bonding/bond0:

Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008)

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

Slave Interface: eth1
MII Status: up
Link Failure Count: 1
Permanent HW addr: 00:aa:bb:cc:dd:ee

Slave Interface: wlan1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:11:22:33:44:55

FIXME Disabling wifi through rfkill (using laptop's switch or touch-sensitive button) removes it from the bond *BUT* re-enabling it won't re-add it. Re-inserting the module after enabling it does add it (e.g. switch on, run # rmmod iwlagn ; modprobe iwlagn).

  • FIXME Can module loading/unloading be hooked to an rfkill event?

Possible troubles

I set up a new computer recently and had to use a couple tricks to get it working. Both the wireless and wired interfaces only worked when the bond was configured to their respective MAC address. My solution was to use the wireless MAC for the bond and put the wired interface in promiscuous mode.

# ifconfig bond0 hw ether 00:11:22:33:44:55
# ifconfig eth1 promisc

Debian's way:

iface bond0 inet dhcp
        # ...
        pre-up ifconfig bond0 hw ether 00:11:22:33:44:55
        pre-up ifconfig eth1 promisc
        post-down ifconfig eth1 -promisc
linux/bonding.txt · Last modified: 2012/07/28 15:40 by Toni Corvera
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki