Linux dual NIC bonding (loading) for load balancing or failover

  
 

The Linux dual NIC binding implementation we introduced here is to use two NICs to become a NIC. The aggregated device looks like a separate Ethernet interface device. Generally speaking, the two NICs have the same IP addresses and parallel links aggregate into a logical link to work. In fact, this technology has long existed in Sun and Cisco. It is called Trunking and Etherchannel technology. It is also used in Linux 2.4.x kernel, called bonding.

The earliest application of bonding technology was designed on clusters ——beowulf to improve data transfer between cluster nodes. Let's discuss the principle of bonding. What is bonding needs to start with the promisc mode of the network card. We know that under normal circumstances, the network card only receives the destination hardware address (MAC Address) is the Ethernet frame of its own Mac, and filters out other data frames to reduce the burden on the driver. But the NIC also supports another mode called promisc, which can receive all the frames on the network, such as tcpdump, which is run in this mode. Bonding also runs in this mode, and the mac address in the driver is modified to change the Mac address of the two network cards to the same, and can receive data frames of a specific mac. The corresponding data frame is then transferred to the bond driver for processing.

It is impossible to set the same IP address directly to two network cards. Kernels 2.4.12 and later are available for the bonding module. Previous versions can be implemented by patch.

First, edit the virtual network interface configuration file, specify the network card IP

Assume that eth0 is the external service network card, and the network has been debugged; eth1 is the network card that wants to provide services with eth0 at the same time. # cd /etc/sysconfig/network-scripts/# vi ifcfg-bond0 The following information is written in the copy code and is similar to the original ifcfg-eth0 configuration.

So I suggest executing the following statement, copying ifcfg-eth0 and then changing it. # cp ifcfg-eth0 The ifcfg-bon0 copy code modifies the information of ifcfg-bon0 as follows: DEVICE=bond0 BOOTPROTO=static IPADDR=[IP] NETMASK=[MASK] BROADCAST=[BROADCAST] GATEWAY=[GATEWAY] ONBOOT=yes TYPE =Ethernet copy code 2, configure real network card

Modify ifcfg-eth0 as follows: DEVICE=eth0 BOOTPROTO=none ONBOOT=yes MASTER=bond0 #If you do not write, you must do the fourth step SLAVE=yes # if not Write, you must do the fourth step USERCTL=yes copy code similarly repair ifcfg-eth1 as follows: DEVICE=eth1 BOOTPROTO=none ONBOOT=yes MASTER=bond0 #If you do not write, you must do the fourth step SLAVE=yes # if not Write, you must do the fourth step USERCTL=yes copy the code three, load the module, let the system support bonding

By default, the kernel has support bonding, just need to simply modify /etc/modprobe.conf this configuration document It can be: add two lines of alias bond0 bonding options bond0 miimon=100 mode=1 copy code description: mode specifies the working mode of bond0, commonly used is 0 and 1, 0 means load balancing mode, 1 means master-slave mode, According to your needs Home. Commonly used are 0, 1 two. Mode=0 indicates that load balancing (round-robin) is the load balancing mode, and both network cards work. Mode=1 indicates that the fault-tolerance (active-backup) provides redundancy. The working mode is the active/standby mode. That is, only one network card works by default and the other is used for backup. Bonding can only provide link monitoring, that is, whether the link from the host to the switch is connected. If only the external link of the switch is down, and the switch itself is not faulty, then bonding will continue to use the link as if there is no problem. Miimon is used for link monitoring. For example: miimon=100, then the system monitors the link connection status every 100ms, and if one line fails, it will transfer to another line.

Four, increase the boot script

Add the ifenslave bond0 eth0 eth1 copy code in /etc/rc.d/rc.local. If eth0 and eth1 both write MASTER and SLAVE, then the above It doesn't matter if you don't do the steps.

5, restart

reboot or service network restart can see the results.

Six, test

Ping an address, of course, can ping the address. If the network is found to be unreachable, check the network settings of ifcfg-bond0.

Then unplug a network cable, if the ping is not broken, it proves that a backup line is pulled, not the main line, and then plugged in again for two minutes.

Unplug another network cable at this time. It is estimated that you can see the ping timeout or the card is there. Wait 10~30 seconds, ping continues.

The test was successful.

Copyright © Windows knowledge All Rights Reserved