Official Documentation: https://help.ubuntu.com/community/UbuntuBonding
Bonding, also known as port aggregation or link aggregation, means combining multiple network interfaces (NICs) into a single link, providing high availability, load balancing, maximum throughput, or a combination of these. See Wikipedia for details.
1. Installation
sudo apt-get install ifenslave
2. Make sure the kernel supports it
Before Ubuntu can configure your network card as NIC bonding, you need to make sure that the correct kernel module bonding is present and loaded at boot time.
Edit your /etc/modules configuration:
sudo vim /etc/modules
Make sure the bonding module is loaded
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
loop
lp
rtc
bonding
Note: As of Ubuntu 9.04, this step is optional if you configure bindings with ifup/ifdown. In this case, the binding module is automatically loaded when the binding interface is brought up.
3. Configure the network interface
Make sure your network is down:
/etc/init.d/networking stop
Then load the bundled kernel module:
sudo modprobe bonding
Now you are ready to configure your NIC.
The general guidelines are:
1. Select which available NICs will be part of the bond.
2. Configure all other network cards as usual
3. Configure all bonded NICs:
1. To configure manually
2. Join the specified bond-master
4. Configure the bound NIC as if it were a normal NIC
5. Add bond specific parameters to the bond NIC as follows.
Edit your interface configuration:
sudo vi /etc/network/interfaces
For example, to use a simple active-backup setup with eth0 and eth1 as active-backup to the bonding interface bond0, and eth0 as the primary interface:
Ethernet bonding can use different modes. You can specify the mode of your bonded interface in /etc/network/interfaces. E.g:
bond-mode 1
There are 7 working modes in bonding
0: (balance-rr) Round-robin policy: (balanced round-robin policy): The order of transmission packets is transmitted in sequence until the last transmission is completed. This mode provides load balancing and fault tolerance.
1: (active-backup) Active-backup policy: (active-backup policy): Only one device is active. One is down and the other is immediately converted to the primary device by the backup. The mac address is externally visible. This mode provides fault tolerance.
2: (balance-xor) XOR policy: (balance-xor): The transmission selects the transmission device according to the boolean value of [(source MAC address xor destination MAC address) mod number of devices]. This mode provides load balancing and fault tolerance.
3: (broadcast) Broadcast policy: (broadcast policy): transmit all data packets to all devices. This mode provides fault tolerance.
4: (802.3ad) IEEE 802.3ad Dynamic link aggregation. IEEE 802.3ad Dynamic link aggregation: Creates aggregation groups that share the same speed and duplex settings. This mode provides fault tolerance. Each device requires driver-based re-acquisition speed and full-duplex support; if a switch is used, the switch also needs to enable 802.3ad mode.
5: (balance-tlb) Adaptive transmit load balancing (adapter transmit load balancing): Channel bonding does not require dedicated switch support. Outgoing traffic is distributed to each device according to the current load. The reception is handled by the current device. If the accepted device fails to communicate, another device will take over the mac address being processed by the current device.
6: (balance-alb) Adaptive load balancing: (adapter load balancing): including mode5, the received load is completed by ARP negotiation. The bonding driver intercepts ARP requests sent by the local system and overwrites the slave device's original address with one of the hardware addresses. It's like different people on the server use different hardware addresses.
If there are multiple bonds? (After testing, it is feasible without this step)
If there are multiple bonds, such as:
eth0 and eth1 make a bond0
eth1 and eth2 make a bond1
Then you need to change the content in /etc/modules to:
bonding mode=1 miimon=100 max_bonds=2
That is, add a max_bonds=2 on the original basis.
The network card configuration part is the same as bond0, except that eth0 and eth1 in the configuration are changed to eth2 and eth3.
over.
Failure test results:
Case 1: eth0 is the master and eth1 is the backup. If eth0 is disconnected, it will automatically switch to eth1. If eth0 is restored, the wiring sequence is: first unplug eth1, then plug in eth0 immediately, and then connect eth1 back
Test environment configuration file:
root@node1:~# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
car ens33
iface ens33 inet manual
bond-master bond0
bond-primary ens33
car ens34
iface ens34 inet manual
bond-master bond0
car ens35
iface ens35 inet manual
bond-master bond1
bond-primary ens35
auto ens36
iface ens36 inet manual
bond-master bond1
auto bond0
iface bond0 inet static
address 192.168.89.160
gateway 192.168.89.2
netmask 255.255.255.0
bond-mode active-backup
bond-miimon 100
bond-slaves none
car bond1
iface bond1 inet static
address 192.168.68.144
netmask 255.255.255.0
bond-mode active-backup
bond-miimon 100
bond-slaves none