Linux uses bonding to achieve dual network redundancy

1 Introduction

Linux bonding is a technology that binds multiple physical NICs into one logical NIC, which can realize functions such as network redundancy, load balancing, and bandwidth expansion. Linux bonding is a module provided in the Linux kernel, which supports seven working modes, and different modes have different characteristics and applicable scenarios. The configuration and management of linux bonding can be carried out through some commands or tools, such as ifenslave, nmcli, ethtool, etc. The status and parameters of linux bonding can be viewed and modified by /proc/net/bonding or ethtool commands.

2. Bonding mode

The bonding technology provides seven working modes, one of which needs to be specified when using it, and each has its own advantages and disadvantages:

mode= 0 : Balanced load mode, with automatic backup, but requires "Switch" support and settings.

mode= 1 : Automatic backup mode, if one line is disconnected, other lines will automatically backup.

mode= 6 : Balanced load mode, with automatic backup, no need for "Switch" support and settings.

It should be noted that if you want to achieve mode 0 load balancing , it is not enough to just set options bond0 miimon= 100 mode=0 here , and the switch connected to the network card must be specially configured (these two ports should be aggregated), because The two network cards used for bonding use the same MAC address . Analyze the principle ( bond runs in mode 0 ):

In mode 0, the IPs of the network cards bound to the bond are all changed to the same mac address. If these network cards are connected to the same switch, then there are multiple the mac address in the arp table of the switch. Then the switch To which port should the packet sent to this mac address be forwarded? Under normal circumstances , the mac address is unique in the world, and one mac address corresponding to multiple ports must confuse the switch. Therefore, if the bond under mode0 is connected to the switch, the ports of the switch should be aggregated ( cisco is called ethernetchannel , and foundry is called portgroup ), because after the switch is aggregated, several ports under the aggregation are also bundled into one mac Address . Our solution is to connect the two network cards to different switches.

In mode6 mode, there is no need to configure a switch, because the two network cards used for bonding use different MAC addresses.

3. Steps to realize dual redundancy mode

  • First, you need to confirm whether the two network cards on your board support the bonding module, and whether your linux system has installed the bonding module. You can use the lsmod | grep bonding command to see if the bonding module is loaded, and if not, you can use the modprobe bonding command to load it.
  • Second, you need to choose an appropriate bonding mode to achieve dual network redundancy. According to your needs, I suggest you use mode=1 (active-backup) mode, in this mode only one network card is active and the other is backup, when the active network card fails, the backup network card will automatically take over the traffic. This mode requires no special configuration of the switch and does not affect network performance.
  • Then, you need to modify the configuration files of the two NICs on your board, and create a bond configuration file. Assuming that your two network cards are eth0 and eth1, then you need to modify the /etc/sysconfig/network-scripts/ifcfg-eth0 and /etc/sysconfig/network-scripts/ifcfg-eth1 files to set them as bond slaves network card. The specific modifications are as follows:

        DEVICE=eth0 # Change the corresponding location of ifcfg-eth1 file to eth1

        USERCTL=no

        ONBOOT=yes

        MASTER=bond0

        SLAVE=yes

        BOOTPROTO=none

        Then, create a file ifcfg-bond0 in the /etc/sysconfig/network-scripts/ directory , set it as the main network card of the bond, and specify the IP address, subnet mask, gateway and other information. The specific content is as follows:

        DEVICE=bond0

        TYPE=Bond

        BOOTPROTO=none

        USERCTL=no

        IPADDR=192.168.1.100 # Modify according to your actual situation

        NETMASK=255.255.255.0 # Modify according to your actual situation

        GATEWAY=192.168.1.1 # Modify according to your actual situation

        BONDING_OPTS="mode=1 miimon=100" # Specify the bonding mode as 1 and the monitoring interval as 100 milliseconds

        ONBOOT=yes

        BONDING_MASTER=yes

  • Finally, you need to restart the network service or restart the board for the configuration to take effect. You can restart the network service with the systemctl restart network command, or reboot the board with the reboot command. After restarting, you can use the cat /proc/net/bonding/bond0 command to view the status and parameters of the bond to confirm whether dual-network redundancy has been successfully implemented.

Guess you like

Origin blog.csdn.net/weixin_44188399/article/details/132692377