Linux bonding

Linux bonding

Linux bonding can bond multiple network interfaces into one network interface to achieve network load balancing and network redundancy. Even if one of the physical NICs fails, it will not cause the network to be disconnected.

Linux Bonding has 7 modes.

model name policy description
mode = 0 balance-rr Round-robin policy The packets are transmitted sequentially in the order of the device until the last device. This mode provides load balancing and fault tolerance.
mode = 1 active-backup Active-backup policy Only one NIC is active, and the other NICs are standby. When the active NIC is fault, and another standby NIC is immediately converted to the primary device. The mac address is externally visible. This mode provides fault tolerance.
mode = 2 balance-xor XOR policy The transmission device is selected based on the result of the MAC address exclusive XOR operation. This mode provides load balancing and fault tolerance.
mode = 3 broadcast Broadcast policy All data packets are transmitted to all interfaces, all data is transmitted through all devices. This mode provides fault tolerance.
mode = 4 802.3ad IEEE 802.3ad Dynamic link aggregation Share the same transfer speed by creating aggregate groups. This mode requires the switch to support 802.3ad mode. This mode provides fault tolerance.
mode = 5 balance-tlb Adaptive transmit load balancing The data to be sent is distributed to each device according to the current load, and the received data is processed by the currently used device. This mode provides load balancing and fault tolerance.
mode = 6 balance-alb Adaptive load balancing This mode includes the balance-tlb mode and increases the receive load balance (rlb) for IPV4. Receive load balance is implemented through ARP negotiation. The bonding driver intercepts the ARP reply sent by the local machine and rewrites the source hardware address to the unique hardware address of a slave in the bond.

Implement Ubuntu bonding in Dell server

Bond the em1 and em2 NIC ports to bond0.

The NIC port name of the Dell server is em1, em2, etc. The name of the NIC port of the Linux system is often eth0, eth1, etc.

1. Edit /etc/network/interfaces file

1
# vim /etc/network/interfaces
1
2
3
4
5
6
7
8
9
10
11
12
13
14
auto lo
iface lo inet loopback

up ifenslave bond0 em1 em2
down ifenslave bond0 -d em1 em2
bond-mode 0
bond-mmimon 100

auto bond0
iface bond0 inet static
address 10.10.4.7
netmask 255.255.255.0
gateway 10.10.4.1
dns-nameserver 202.106.0.20

You do not need to configure the em1, em2 port information, you just need to configure the IP address and other information on the Bond(bond0).

2. Edit /etc/modules file

1
vim /etc/modules

Add to file.

1
bonding

3. execute the command

1
# modprobe bonding

4. Then restart the server.

5. Create and delete Bond

bond0 can be created automatically after reboot.
You can manually create and delete bond0 by editing the file /sys/class/net/bonding_masters.

Create a new Bond(bond0):

1
# echo +bond0 > /sys/class/net/bonding_masters

Delete a exist Bond(bond0):

1
# echo -bond0 > /sys/class/net/bonding_masters

Show all Bonds:

1
# cat /sys/class/net/bonding_masters

6. Create and delete Slave

You can make port belong to bond by editing the file /sys/class/net/bond/bonding/slaves.

Make port em1, em2 belong to bond0:

1
2
# echo +em1 > /sys/class/net/bond0/bonding/slaves
# echo +em2 > /sys/class/net/bond0/bonding/slaves

Release Slave(em1,em2) from Bond(bond0):

1
2
# echo -em1 > /sys/class/net/bond0/bonding/slaves
# echo -em2 > /sys/class/net/bond0/bonding/slaves

7. Install the ifenslave

After adding the em1, em2 port to the slaves of bond0, you can temporarily access the Internet (the network will disconnected again after the restart), so install the ifenslave now.

1
2
# apt-get update
# apt-get install ifenslave

Now, the network will always be connected, even if you reboot later.

8. Show bond0 status

1
cat /proc/net/bonding/bond0

Displaying up means successful:

1
MII Status: up

And down means not enabled, there may be not automatically enabled, you can try to start it manually:

1
ifconfig bond0 up