1, Introduction
There are seven (0 ~ 6) network card binding mode s: bond0, bond1, bond2, bond3, bond4, bond5 and bond6.
Three commonly used:
mode=0: Load balancing mode, with automatic backup, but need " Switch"Support and setup. mode=1: Automatic backup mode, if one line is broken, the other lines will be automatically backup. mode=6: Load balancing mode, with automatic backup, not necessary " Switch"Support and setup.
2, Detailed explanation and experiment of seven models
2.1. Mode = 0 (balance RR)
Link load balancing, increasing bandwidth and supporting fault tolerance. A link failure will automatically switch to a normal link. The switch needs to be configured with an aggregation port. Cisco calls it a port channel.
characteristic
The transmission sequence of data packets is sequential transmission (that is, the first packet goes eth0, the next packet goes eth1... And continues to cycle until the last transmission is completed). This mode provides load balancing and fault tolerance; However, we know that if the data packets of a connection or session are sent from different interfaces and pass through different links halfway, the problem of disorderly arrival of data packets is likely to occur at the client, and the disorderly arrival data packets need to be sent again, so the network throughput will be reduced
2.2. Mode = 1 (active backup) (primary backup strategy)
This is the active standby mode. Only one network card is active and the other is standby. All traffic is processed on the active link. If the switch is configured with binding, it will not work because the switch sends out packets to two network cards, and half of the packets are discarded.
characteristic
Only one device is active. When one device goes down, the other is immediately converted from backup to primary. The MAC address is externally visible. From the outside, the MAC address of bond is unique to avoid confusion in the switch. This mode only provides fault tolerance; It can be seen that the advantage of this algorithm is that it can provide high network connection availability, but its resource utilization is low. Only one interface is working. When there are N network interfaces, the resource utilization is 1/N
2.3. Mode = 2 (balance XOR) (balance strategy)
Indicates XOR Hash load sharing, which is matched with the aggregation forced non negotiation mode of the switch. (xmit_hash_policy and port channel configuration are required)
characteristic
Transmits packets based on the specified HASH policy. The default policy is: (source MAC address XOR destination MAC address)% number of slave. Other transmission strategies can be implemented through Xmit_ HASH_ The policy option specifies that this mode provides load balancing and fault tolerance
2.4. Mode = 3 (broadcast) (broadcast strategy)
It means that all packets are sent from all network interfaces. This is unbalanced. There is only redundancy mechanism, but it is too wasteful of resources. This model is applicable to the financial industry because they need a highly reliable network and do not allow any problems. It needs to cooperate with the aggregation forced non negotiation mode of the switch.
characteristic
Each packet is transmitted on each slave interface. This mode provides fault tolerance
2.5. mode=4(802.3ad)(IEEE 802.3ad dynamic link aggregation)
Indicates that it supports 802.3ad protocol and cooperates with the aggregated LACP mode of the switch (xmit_hash_policy is required) The standard requires all devices to operate at the same rate and duplex mode during aggregation. Moreover, like other bonding load balancing modes except Balance RR mode, no connection can use the bandwidth of more than one interface.
characteristic
1. Create an aggregation group that shares the same rate and duplex settings. According to 802.3ad specification, multiple slave s work in the same activated polymer.
2. The slave election of outgoing traffic is based on the transmission hash policy, which can be implemented through Xmit_ hash_ The policy option changes from the default XOR policy to another policy. It should be noted that not all transmission strategies are 802.3ad compliant,
3. In particular, the packet disorder mentioned in chapter 43.2.4 of 802.3ad standard is considered. Different implementations may have different adaptability.
2.6. Mode = 5 (balance TLB) (adapter transmission load balancing)
Select a slave to send according to the load of each slave, and use the current slave when receiving. This mode requires the network device driver of the slave interface to have some kind of ethtool support; And ARP monitoring is not available.
characteristic
Channel bonding that does not require any special switch support. On each slave, outgoing traffic is distributed according to the current load (calculated according to speed). If the slave receiving data fails, another slave takes over the MAC address of the failed slave.
2.7. Mode = 6 (balance ALB) (adapter adaptive load balancing)
RLB (receive load balance) is added to the tlb of 5 No switch support is required. Receiving load balancing is realized through ARP negotiation
characteristic
This mode includes the balance TLB mode, plus receive load balance (RLB) for IPV4 traffic, and does not need any switch support. Receiving load balancing is realized through ARP negotiation. The binding driver intercepts the ARP response sent by the local machine and rewrites the source hardware address into the unique hardware address of a slave in the bond, so that different opposite ends can communicate with different hardware addresses.
In fact, the difference between mod=6 and mod=0
mod=6, first fill eth0, then eth1 ethX; If mod=0, it will be found that the traffic of the two ports is very stable, with basically the same bandwidth. When mod=6, it will be found that the flow of the first port is very high, and the second port only accounts for a small part of the flow.
experiment
1) First, it depends on whether linux supports binding. Most distributions support binding
$ modinfo bonding |more filename: /lib/modules/4.18.0-305.3.1.el8.x86_64/kernel/drivers/net/bonding/bonding.ko.xz author: Thomas Davis, tadavis@lbl.gov and many others description: Ethernet Channel Bonding Driver license: GPL alias: rtnl-link-bond rhelversion: 8.4 srcversion: 445F4CC9A2F7E64E3A87FD0 depends: intree: Y name: bonding vermagic: 4.18.0-305.3.1.el8.x86_64 SMP mod_unload modversions sig_id: PKCS#7 signer: CentOS kernel signing key sig_key: 1B:76:0B:00:B4:46:42:E5:5A:5D:E3:52:84:E5:35:67:94:50:0B:72 sig_hashalgo: sha256 .... ....
If the above information is output, it indicates that binding is supported. If not, it indicates that the kernel does not support binding and needs to be recompiled.
2) Preliminary preparation instructions
2 The physical network ports are: ens33,ens37 The bound virtual port is: bond0 bond0 Bound IP Yes: 192.168.182.130
3) Modify ens33 configuration file
DEVICE=bond0 NAME='System bond0' TYPE=Ethernet NM_CONTROLLED=no USERCTL=no ONBOOT=yes BOOTPROTO=none IPADDR=192.168.182.130 NETMASK=255.255.255.0 GATEWAY=182.168.182.2 #BONDING_OPTS='mode=0 miimon=100' # You can not write the schema configuration directly in the configuration file IPV6INIT=no
4) Modifying the binding configuration file
CentOS6 added write / etc / modprobe D / dist.conf, CentOS7 creates / etc / modprobe d/bonding. conf
$ echo 'alias bond0 bonding' >> /etc/modprobe.d/bonding.conf $ echo 'options bond0 miimon=100 mode=0' >> /etc/modprobe.d/bonding.conf
Parameter interpretation
miimon: The frequency of monitoring network links is in milliseconds. We set it to 100 milliseconds every 100 milliseconds (That is, 0.1 second) Monitor the connection status of primary circuit. If one circuit is blocked, turn to another circuit; Linux The multi network card binding function of uses the binding function in the kernel"bonding"modular mode: bond Mode. In general practical applications, 0 and 1 are used more
5) Loading the binding module
$ modprobe bonding
Confirm whether the module is loaded successfully
$ lsmod |grep bonding
6) Restart the network
service network restart
7) View bond
$ cat /proc/net/bonding/bond0
3, Use the nmcli command to create a bond card (Centos8 also applies)
3.1. Add a new connection and bind the network card mode (bind 0 here)
$ nmcli connection add type bond ifname bond0 mode 0 $ nmcli connection add type bond-slave ifname ens33 master bond0 $ nmcli connection add type bond-slave ifname ens37 master bond0
delete
$ nmcli connection delete bond-bond0 # Delete bond0 $ nmcli connection delete bond-slave-ens33 # Delete ens33 $ nmcli connection delete bond-slave-ens37 # Delete 37
3.2. Modify the generated configuration file (/ etc / sysconfig / network scripts / ifcfg-bond-bond0)
1) Change BOOTPROTO=dhcp to BOOTPROTO=static
2) Add the following configuration at the end
IPADDR=192.168.182.152 PREFIX=24 GATEWAY=192.168.182.2 DNS1=8.8.8.8
Full configuration
BONDING_OPTS=mode=balance-rr TYPE=Bond BONDING_MASTER=yes PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=bond-bond0 UUID=59899e5d-49cf-44a0-af87-fca29472afd5 DEVICE=bond0 ONBOOT=yes IPADDR=192.168.182.152 PREFIX=24 GATEWAY=192.168.182.2 DNS1=8.8.8.8
3.3. Reload all network card configurations
nmcli networking off && nmcli networking on
3.4. View bond
4, Expand
Above, two network cards (ens33 and ens37) are bound into a bond0. If we want to set multiple bond ports, for example, the physical network ports ens33 and ens37 form bond0, and ens37 and ens38 form bond1, the setting method of the network port setting file is the same as above
It's the same, except / etc / modprobe d/bonding. Conf files cannot be superimposed. There are two correct setting methods:
First kind
alias bond0 bonding alias bond1 bonding options bonding max_bonds=2 miimon=200 mode=1
Parameter interpretation
miimon: The frequency of monitoring network links, in milliseconds, is set to 100 milliseconds mode: bond Mode. In general practical applications, 0 and 1 are used more max_bonds: Configured bond Number of ports
In this way, all bindings can only use one mode.
Second
alias bond0 bonding options bond0 miimon=100 mode=1 install bond1 /sbin/modprobe bonding -o bond1 miimon=100 mode=0 install bond2 /sbin/modprobe bonding -o bond2 miimon=100 mode=1 install bond3 /sbin/modprobe bonding -o bond3 miimon=100 mode=0
In this way, different bond ports can be set to different mode s. Note that / etc / rc d/rc. Setting of local file
ifenslave bond0 eth0 eth1 ifenslave bond1 eth2 eth3 ifenslave bond2 eth4 eth5 ifenslave bond3 eth6 eth7