1. Working mode of Bond
Linux binding driver can bind multiple network cards into a logical network card for network load balancing and network redundancy.
bonding has seven working mode s:
1) , mode=0, (balance RR) (polling equalization mode)
Data packets are transmitted in sequence until the last transmission is completed. This mode provides load balancing and fault tolerance. The server has only one MAC address, and its physical network card has no MAC address. Therefore, the switch needs to do link aggregation, otherwise it does not know which network card to send the data packet to
2) , mode=1, (active backup) (active standby mode)
Only one master is active. One goes down and the other is immediately converted from backup to primary device. The mac address is externally visible. This mode provides fault tolerance. No special configuration of the switch is required. Just configure the access port.
3) , mode=2, (balance XOR) (balance strategy)
Features: transmit packets based on the specified HASH policy. This mode provides load balancing and fault tolerance.
4) , mode=3, (broadcast) (broadcast strategy)
Features: each data packet is transmitted on each network card. There are too many broadcast packets. Generally, this mode is not used. Transfer all packets to all devices. This mode provides fault tolerance.
5) , mode=4, (802.3ad) IEEE 802.3ad dynamic link aggregation
Create an aggregation group that shares the same speed and duplex settings. This mode provides fault tolerance. Each device needs driver based re acquisition speed and full duplex support; If a switch is used, the switch also needs to enable 802.3ad mode.
6) , mode=5, (balance TLB) adaptive transmit load balancing
Features: no special switch is required to support channel bonding. Distribute outgoing traffic on each network card according to the current load (calculated according to speed). If the network card receiving data fails, another network card takes over the MAC address of the failed network card. The MAC of multiple network cards can be seen on the switch, so the switch does not need to be configured for link aggregation.
7) , mode=6, (balance ALB) adaptive load balancing:
Features: this mode includes the balance TLB mode, plus the receive load balance (RLB) for IPV4 traffic, and does not need any switch support. The MAC of multiple network cards can also be seen on the switch, and link aggregation configuration is not required.
The following is the implementation principle of mode=6
1.bond receiving load balancing is realized through ARP protocol. The binding driver intercepts the ARP response sent by the local machine and rewrites the source MAC address into the MAC address of a network card in the bond, so that the ARP learned on the switch is the MAC address that the server wants to allocate traffic, and the traffic sent to the server will be sent to the corresponding mac address.
2.bond transmission load balancing is also realized through ARP protocol. When the server initiates an ARP request, the binding driver copies and saves the IP information of the opposite end from the ARP packet. When the ARP response arrives from the opposite end, the binding driver extracts its MAC address and forges an ARP response to a network card in the bond, so as to send data packets from the specified network card.
3. When a network card fails or ARP expires, bond will recalculate and redistribute the traffic to each network card.
2. Configuration steps
The following steps are the binding steps of configuring dual network cards with mode=6, and the methods of other modes are the same;
2.1. Install ifenslave software
fenslave is a kind of glued and separated software, which can effectively allocate data packets to binding drivers
sudo apt install ifenslave
2.2. / etc/modules file
Add the following configuration in the / etc/modules file
bonding mode=6 miimon=100
mode=6 means mode 6 is adopted;
Miimon is used for link monitoring. For example, miimon=100 means that the system monitors the link connection status every 100ms. If one line fails, switch to another line.
2.3. Modify / etc/network/interfaces file configuration
First, you need to determine the name of the network card interface. You can view it through the ifconfig command. The current network card interfaces are ens33 and ens34 respectively; Add the following configuration in the / etc/network/interfaces File
# Dual network card configuration auto ens33 iface ens33 inet manual bond-master bond0 auto ens34 iface ens34 inet manual bond-master bond0 auto bond0 iface bond0 inet static address 192.168.20.10 netmask 255.255.255.0 gateway 192.168.20.2 dns-nameservers 192.168.20.1 220.127.116.11 bond-slaves ens33 ens34 bond-lacp-rate 1 bond-mode 6 bond-miimon 100
2.4. Loading the binding module
# Load module $ sudo modprobe bonding # View the module. If the module has been loaded, it will be displayed $ sudo lsmod|grep bonding bonding 163840 0
2.5. Viewing status
View network configuration
$ ifconfig bond0 Link encap:Ethernet Hardware address 00:0c:29:34:7a:4a inet address:192.168.20.10 radio broadcast:192.168.20.255 Mask:255.255.255.0 inet6 address: fe80::20c:29ff:fe34:7a4a/64 Scope:Link UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric :1 Receive packet:964 error:0 discard:0 overload:0 Number of frames:0 Send packet:4205 error:0 discard:0 overload:0 carrier:0 collision:0 Send queue length:1000 Receive byte:75022 (75.0 KB) Send byte:300032 (300.0 KB) ens33 Link encap:Ethernet Hardware address 00:0c:29:34:7a:4a UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric :1 Receive packet:2740 error:0 discard:0 overload:0 Number of frames:0 Send packet:3416 error:0 discard:0 overload:0 carrier:0 collision:0 Send queue length:1000 Receive byte:3899473 (3.8 MB) Send byte:278409 (278.4 KB) ens34 Link encap:Ethernet Hardware address 00:0c:29:34:7a:54 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric :1 Receive packet:1369 error:0 discard:0 overload:0 Number of frames:0 Send packet:2125 error:0 discard:0 overload:0 carrier:0 collision:0 Send queue length:1000 Receive byte:106846 (106.8 KB) Send byte:139061 (139.0 KB)
Viewing binding status
$ cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: adaptive load balancing Primary Slave: None Currently Active Slave: ens33 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: ens33 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:34:7a:4a Slave queue ID: 0 Slave Interface: ens34 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:34:7a:54 Slave queue ID: 0
2.6 verification test
Physically close a network card (unplug the network cable)
# Before shutdown, the rate is 2000Mb/s $ ethtool bond0 Settings for bond0: Supported ports: [ ] Supported link modes: Not reported Supported pause frame use: No Supports auto-negotiation: No Advertised link modes: Not reported Advertised pause frame use: No Advertised auto-negotiation: No Speed: 2000Mb/s Duplex: Full Port: Other PHYAD: 0 Transceiver: internal Auto-negotiation: off Cannot get wake-on-lan settings: Operation not permitted Link detected: yes # After shutdown, the rate becomes 1000Mb/s $ ethtool bond0 Settings for bond0: Supported ports: [ ] Supported link modes: Not reported Supported pause frame use: No Supports auto-negotiation: No Advertised link modes: Not reported Advertised pause frame use: No Advertised auto-negotiation: No Speed: 1000Mb/s Duplex: Full Port: Other PHYAD: 0 Transceiver: internal Auto-negotiation: off Cannot get wake-on-lan settings: Operation not permitted Link detected: yes
Note: you cannot use ifdown to turn off the network card, which will cause network interruption
Linux bonding has seven working modes. If you want to increase the throughput of the network card, you usually use the mode of mode=6. If you pay attention to the stability of the network, you usually use the mode of mode=1
4. Reference articles
Ubuntu configures dual network card binding to achieve load balancing (example code):
Linux multi network card bond mode VS switch link aggregation:
linux multi network card binding aggregation bond technology: