We will introduce how to bind two NICs in Linux to a virtual network card. The aggregated device looks like a separate Ethernet interface device, in general, two NICs have the same IP address, and parallel links are aggregated into a logical link. In fact, this technology already exists in Sun and Cisco, known as Trunking and Etherchannel technology. It is also used in Linux 2.4.x kernel, known as bonding.
The earliest application of bonding technology was on the cluster beowulf, designed to improve data transmission between cluster nodes. Next we will discuss the principles of bonding. What is bonding? It should start with the promisc mode of the NIC. We know that, under normal circumstances, the network adapter only receives the target hardware Address (MAC Address) as its own Mac Ethernet frame, and filters out all other data frames to reduce the burden on the driver. However, the NIC also supports another mode called hybrid promisc, which can receive all frames on the network. For example, tcpdump runs in this mode. Bonding also runs in this mode, and modifies the mac address in the driver, changing the Mac address of the two NICs to the same, can receive data frames of a specific mac. Then, the data frame is sent to the bond driver for processing.
It is impossible to directly set the same IP address for the two NICs. Kernels 2.4.12 and later versions are provided for the bonding module. Previous versions can be implemented through patch.
1. Edit the virtual network interface configuration file and specify the nic ip Address
Assume that eth0 is the NIC for external services and has already debugged the network. eth1 is the NIC for external services at the same time as eth0.
# Cd/etc/sysconfig/network-scripts/
# Vi ifcfg-bond0
Writing the following information is similar to the configuration of the original ifcfg-eth0.
So I suggest you execute the following statement to copy the ifcfg-eth0 and then modify it.
# Cp ifcfg-eth0 ifcfg-bon0
Modify the ifcfg-bon0 information as follows:
DEVICE = bond0
BOOTPROTO = static
IPADDR = [IP]
NETMASK = [MASK]
BROADCAST = [BROADCAST]
GATEWAY = [GATEWAY]
ONBOOT = yes
TYPE = Ethernet
2. Configure the real Nic
Modify ifcfg-eth0 as follows:
DEVICE = eth0
BOOTPROTO = none
ONBOOT = yes
MASTER = bond0 # If no write is performed, step 4 is required.
SLAVE = yes # if not written, step 4 is required.
USERCTL = yes
Similar repair ifcfg-eth1 is as follows:
DEVICE = eth1
BOOTPROTO = none
ONBOOT = yes
MASTER = bond0 # If no write is performed, step 4 is required.
SLAVE = yes # if not written, step 4 is required.
USERCTL = yes
3. Load the module so that the system supports bonding
By default, the kernel supports bonding. You only need to modify the configuration file/etc/modprobe. conf to add two lines.
Alias bond0 bonding
Options bond0 miimon = 100 mode = 1
Note:
Mode specifies the bond0 working mode. Commonly Used 0 and 1 are used to indicate the load balancing mode, and 1 is the Master/Slave mode. You can configure it as needed. Commonly used are 0, 1. Mode = 0 indicates that the load balancing (round-robin) method is load balancing, and both NICs work. Mode = 1 indicates that fault-tolerance (active-backup) provides redundancy, working in the active/standby mode. That is to say, by default, only one network card works and the other is backed up. Bonding can only provide link monitoring, that is, whether the link from the host to the switch is connected. If the external link of the switch is down and the switch is not faulty, bonding considers that the link is correct and continues to be used. Miimon is used for link monitoring. For example: miimon = 100, The system monitors the link connection status every Ms. If one line fails, it is transferred to another line.
4. Add boot script
Add/etc/rc. d/rc. local
Ifenslave bond0 eth0 eth1
If both eth0 and eth1 write MASTER and SLAVE, the above steps do not matter.
5. Restart
Reboot or service network restart can see the results.
Vi. Test
Ping An address. Of course, the address can be pinged. If network connectivity is found, check the network settings for the ifcfg-bond0.
Then unplug a network cable. If the ping is not broken, it indicates that a backup line is unplugged. If it is not the main line, re-plug it for two minutes.
At this time, unplug the other network cable. Now we can see that the ping times out or is stuck there. Please wait for 10 ~ 30 seconds. ping continues.
The test is successful.