bonding eth0 wlan0 together to get an active backup link

21 jun 2012

#what is this?

for years i wanted to be able to change from a wireless setup to a wired one in a transparent fashion, that is:

  • without having to configure
  • without loosing active connections
  • with the ability to expand bandwidth when needed

but altough this seems to be a default on mac os x and maybe on windows vista+ (not sure for windows) it never worked on linux. this was probably caused by the fact: that i tried to use a bridge at first and wlan does not go well together with ethernet (kernel related limitiation; maybe MTU settings?).

i can’t remember why bonding failed last time i tried it (2years ago?) - maybe because of the used linux drivers?

how does it work?

OXIGEN ICON THEME Oxygen icon theme is dual licensed. You may copy it under the Creative Common Attribution-ShareAlike 3.0 License or the GNU Library General Public License. i created this image; please feel free to use either of the above liceneses when using my composition of the image (nixos_bonding.png)

first read the manual at [1]. here is the sequence of actions i had to take:

# rmmod bonding
# modprobe bonding mode=active-backup miimon=100 primary=eth0
# ifconfig bond0 up
# ifenslave bond0 eth0 --verbose

since wlan drivers are somehow odd from time to time i usually prefer to shut wlan0 down:

# ip l set wlan0 down

my first and failed attempt to to get wlan0 to bond0:

# ifenslave bond0 wlan0 --verbose
ifenslave.c:v1.1.0 (December 1, 2003)
o Donald Becker (becker@cesdis.gsfc.nasa.gov).
o Detach support added on 2000/10/02 by Willy Tarreau (willy at meta-x.org).
o 2.4 kernel support added on 2001/02/16 by Chad N. Tindel
 (ctindel at ieee dot org).
ABI ver is 2
current hardware address of master 'bond0' is 00:23:7d:00:ff:fe, type 1
Interface 'wlan0': flags set to 1002.
Interface 'wlan0': address cleared
Master 'bond0': Error: SIOCBONDENSLAVE failed: Operation not possible due to RF-kill
Master 'bond0': hardware address set to 00:23:7d:00:ff:fe.
Slave 'wlan0': MTU set to 1500.
Master 'bond0', Slave 'wlan0': Error: Enslave failed

so after disabling the RF-kill (i have a wlan rf-kill switch on the keyboard)

# ifenslave bond0 wlan0

just to make sure all services work as expected, i restart them:

# stop dhcpcd
# dhcpcd bond0
 
# stop wpa_supplicant
# start wpa_supplicant

# ip a
 2: eth0:  mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
    link/ether 00:23:7d:00:ff:fe brd ff:ff:ff:ff:ff:ff
 3: wlan0:  mtu 1500 qdisc mq master bond0 state UP qlen 1000
    link/ether 00:23:7d:00:ff:fe brd ff:ff:ff:ff:ff:ff
 5: bond0:  mtu 1500 qdisc noqueue state UP
    link/ether 00:23:7d:00:ff:fe brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.105/24 brd 192.168.2.255 scope global bond0
    inet6 fe80::223:7dff:fe00:6ec8/64 scope link
    valid_lft forever preferred_lft forever

note:

  • eth0/wlan0/bond0 all share the same mac address now
  • eth0/wlan contain tha SLAVE flag
  • all are in state UP

also note: i do not use wicd/network manager

# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=50 time=30.8 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=50 time=28.4 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=50 time=30.5 ms (here i unplug eth0)
64 bytes from 8.8.8.8: icmp_req=4 ttl=50 time=30.5 ms
64 bytes from 8.8.8.8: icmp_req=5 ttl=50 time=31.4 ms
64 bytes from 8.8.8.8: icmp_req=6 ttl=50 time=30.9 ms
64 bytes from 8.8.8.8: icmp_req=7 ttl=50 time=32.2 ms
^C
--- 8.8.8.8 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6008ms
rtt min/avg/max/mdev = 28.420/30.708/32.215/1.105 ms

i also did some bandwidth tests downloading a big file from my local samba server and it changed from slow when being on wlan to fast when plugging in the cable (took about 1-3 seconds)

the only problem so far: * konqueror won’t resolve smb://foobar/ to the smb://192.168.2.104 ip

this might be caused as i use the code below in my smb.conf, see [2]:

server string = foobar
netbios name = foobar

and netbios might have problems with this setup (but i doubt that, it is probably some konqueror related issue)

requirements

hope i covered all requirements:

  • the LAN and WLAN have to be bridged on the router, thus both have to be in the same collision domain (this means that both lan/wlan share the same ip range and devies bound to either can see each others MAC addresses)
  • i use wpa_supplicant and wpa2 encryption, so wpa_supplicant must work when using encryption
  • lspci showed:
    • 03:00.0 Network controller: Intel Corporation Ultimate N WiFi Link 5300
    • 00:19.0 Ethernet controller: Intel Corporation 82567LM Gigabit Network Connection (rev 03)
  • Linux eliteBook-8530w 3.2.20 #1 SMP Tue Jun 12 22:57:17 UTC 2012 x86_64 GNU/Linux
  • ifenslave.c: v1.1.0 (December 1, 2003)
    • it might make sense to call ifenslave with –verbose because only then one can see that

summary

i will make this a default setup for sure:

  • yet i need to package ifenslave as i can’t find it on nixpkgs
  • maybe bonding should be integrated similar to “networking.bridging”, see [3]
  • i wonder how wicd might be affected by bonding

anyway, to see this working at least is a good thing!

article source