Debian: how to create/remove bonding device

root's picture

Adding a bonding device

1. install ifenslave package:

core:~# aptitude install ifenslave
Note: selecting "ifenslave-2.6" instead of the
      virtual package "ifenslave"
The following NEW packages will be installed:
  ifenslave-2.6 
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 18.4 kB of archives. After unpacking 143 kB will be used.
Get:1 http://ftp.debian.org/debian/ squeeze/main ifenslave-2.6 amd64 1.1.0-17 [18.4 kB]
Fetched 18.4 kB in 0s (63.1 kB/s)
Selecting previously deselected package ifenslave-2.6.
(Reading database ... 175297 files and directories currently installed.)
Unpacking ifenslave-2.6 (from .../ifenslave-2.6_1.1.0-17_amd64.deb) ...
Processing triggers for man-db ...
Setting up ifenslave-2.6 (1.1.0-17) ...
update-alternatives: using /sbin/ifenslave-2.6 to provide /sbin/ifenslave (ifenslave) in auto mode.

2. If you have the slave interface (in our example eth1 and eth2) already configured, remove their configuration from /etc/network/interfaces and add the following instead (in the same file):

auto bond0
iface bond0 inet static
        address 192.168.11.1
        netmask 255.255.255.0
        network 192.168.11.0
        broadcast 192.168.11.255
        slaves eth1 eth2
        bond_mode active-backup
        bond_miimon 100
        bond_downdelay 200
        bond_updelay 200

3. Flush the ip configuration on eth1 and eth2:

core:~# ip address show dev eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc pfifo_fast master bond0 state UNKNOWN qlen 1000
    link/ether 00:22:b0:68:73:4d brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.1/24 brd 192.168.10.255 scope global eth1
core:~# [color=green]ip address flush dev eth1[/color]
core:~# ip address show dev eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc pfifo_fast master bond0 state UNKNOWN qlen 1000
    link/ether 00:22:b0:68:73:4d brd ff:ff:ff:ff:ff:ff

core:~# ip address show dev eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
    link/ether 00:22:b0:68:73:4d brd ff:ff:ff:ff:ff:ff
    inet 192.168.69.1/24 brd 192.168.69.255 scope global eth2
core:~# [color=green]ip address flush dev eth2[/color]
core:~# ip address show dev eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
    link/ether 00:22:b0:68:73:4d brd ff:ff:ff:ff:ff:ff

4. start the bond device (on my server samba was restarted automatically, it may not be the case on yours):

core:~# ifup bond0
Starting Samba daemons: nmbd smbd.

5. restart the networking:

core:~# /etc/init.d/networking restart
done.
core:~#

6. You should now have your bond device active:

core:~# ifconfig bond0
bond0     Link encap:Ethernet  HWaddr 00:22:b0:68:73:4d  
          inet addr:192.168.10.1  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:2623 errors:0 dropped:0 overruns:0 frame:0
          TX packets:81 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:415762 (406.0 KiB)  TX bytes:14461 (14.1 KiB)

You can check the bonding interface status with the following commands:

core:~# cat /sys/class/net/bond0/bonding/mode
active-backup 1
core:~# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008)

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

Slave Interface: eth1
MII Status: down
Link Failure Count: 0
Permanent HW addr: 00:22:00:89:03:00

Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:24:00:70:A1:00

NOTE: if you have dhcpd server configured for one of the interfaces eth1 and eth2, do not forget to modify it and restart it also:

core:~# cat /etc/default/isc-dhcp-server | egrep -v "^$|^#"
INTERFACES="bond0"
core:~# /etc/init.d/isc-dhcp-server restart
Stopping ISC DHCP server: dhcpd.
Starting ISC DHCP server: dhcpd.

Regarding bond_mode in the point 1, I have opted for active-backup but there are other options too. Below you can read about all of them:

Mode 0 (balance-rr)

This mode transmits packets in a sequential order from the first available slave through the last. If two real interfaces are slaves in the bond and two packets arrive destined out of the bonded interface the first will be transmitted on the first slave and the second frame will be transmitted on the second slave. The third packet will be sent on the first and so on. This provides load balancing and fault tolerance.

Mode 1 (active-backup)

This mode places one of the interfaces into a backup state and will only make it active if the link is lost by the active interface. Only one slave in the bond is active at an instance of time. A different slave becomes active only when the active slave fails. This mode provides fault tolerance.

Mode 2 (balance-xor)

Transmits based on XOR formula. (Source MAC address is XOR’d with destination MAC address) modula slave count. This selects the same slave for each destination MAC address and provides load balancing and fault tolerance.

Mode 3 (broadcast)

This mode transmits everything on all slave interfaces. This mode is least used (only for specific purpose) and provides only fault tolerance.

Mode 4 (802.3ad)

This mode is known as Dynamic Link Aggregation mode. It creates aggregation groups that share the same speed and duplex settings. This mode requires a switch that supports IEEE 802.3ad Dynamic link.

Mode 5 (balance-tlb)

This is called as Adaptive transmit load balancing. The outgoing traffic is distributed according to the current load and queue on each slave interface. Incoming traffic is received by the current slave.

Mode 6 (balance-alb)

This is Adaptive load balancing mode. This includes balance-tlb + receive load balancing (rlb) for IPV4 traffic. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the server on their way out and overwrites the src hw address with the unique hw address of one of the slaves in the bond such that different clients use different hw addresses for the server.

Removing a bonding device

1. Remove the bond configuration from /etc/network/interfaces

2. Unconfigure the bonding device: echo "-bond0" > /sys/class/net/bonding_masters

3. Restart the networking.

Example:
root@candy:~# ifconfig bond0
bond0     Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          inet addr:192.168.69.12  Bcast:192.168.69.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe74:91af/64 Scope:Link
          UP BROADCAST MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

root@candy:~# ip addr flush dev bond0
root@candy:~# ifconfig bond0
bond0     Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          BROADCAST MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

root@candy:~# cat /sys/class/net/bonding_masters
bond0
root@candy:~# echo "-bond0" > /sys/class/net/bonding_masters
root@candy:~# ifconfig bond0
bond0: error fetching interface information: Device not found
root@candy:~# rmmod bonding

PS: If you want to configure bonding on VirtualBox, you have to use bridged adapter. However, if you are fixed on internal network, it will not work. Still, I have managed to create a working balance-rr bonding interface by configuring two internal network interfaces with same mac address in VirtualBox. Not tested it enough tho.

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content

root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root