Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction of seven modes of binding dual network cards under Linux

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "introduction of seven modes of binding dual network cards under Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The principle of seven bond modes of multiple network cards

There are seven types of mode bound to Linux Nic (066) bond0, bond1, bond2, bond3, bond4, bond5, bond6

There are three commonly used ones.

Mode=0: load balancing mode, with automatic backup, but requires "Switch" support and setting.

Mode=1: automatic backup mode. If one line is disconnected, the other lines will be backed up automatically.

Mode=6: load balancing mode, automatic backup, no need for "Switch" support and setting.

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

The IP of the network card bound to bond under mode 0 is modified to the same mac address. If these network cards are all connected to the same switch, there will be multiple ports corresponding to the mac address in the arp table of the switch. Which port should the switch forward packets destined for this mac address? Normally, mac addresses are unique in the world, and a single mac address corresponds 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,foundry and portgroup), because after the switch has done aggregation, several ports under the aggregation are also bundled into a mac address. Our solution is that two network cards can be connected to different switches.

There is no need to configure the switch in mode6 mode because the two network cards for bonding use different MAC addresses.

Seven bond modes explain

The first mode: mod=0, that is: (balance-rr) Round-robin policy (balanced cycle strategy)

Features: the order of transmitting data packets is to transmit in turn (that is, the first packet goes eth0, the next packet goes eth2. . This mode provides load balancing and fault tolerance until the last transmission is completed), but we know that if the packets of a connection or session are sent from different interfaces and pass through different links halfway, the problem of packet disorderly arrival is likely to occur on the client, and disorderly packets need to be re-required to be sent, so that the throughput of the network will decline.

The second mode: mod=1, namely: (active-backup) Active-backup policy (master-backup strategy)

Features: only one device is active, when one goes down and the other is immediately switched to the primary device by backup. The mac address is externally visible, and from the outside, the MAC address of the bond is unique to avoid confusion in the switch (switch). This mode only provides fault tolerance; thus it can be seen that the advantage of this algorithm is that it can provide high availability of network connections, but its resource utilization is low, only one interface is working, and when there are N network interfaces, the resource utilization rate is 1max N

The third mode: mod=2, namely: (balance-xor) XOR policy (balancing strategy)

Features: data packets are transmitted based on the specified transmission HASH policy. The default policy is: (source MAC address XOR destination MAC address)% number of slave. Other transport policies can be specified through the xmit_hash_policy option, which provides load balancing and fault tolerance

The fourth mode: mod=3, namely: broadcast (broadcast strategy)

Features: transmitting each packet on each slave interface, this mode provides fault tolerance

The fifth mode: mod=4, namely: (802.3ad) IEEE 802.3ad Dynamic link aggregation (IEEE 802.3ad dynamic link aggregation)

Features: create an aggregation group that shares the same speed and duplex settings. Multiple slave work under the same active polymer according to the 802.3ad specification.

The slave election for outbound traffic is based on the transport hash policy, which can be changed from the default XOR policy to other policies through the xmit_hash_policy option. It should be noted that not all transmission strategies are 802.3ad adaptive, especially considering the packet disorder mentioned in section 43.2.4 of 802.3ad standard. Different implementations may have different adaptations.

Necessary conditions:

Conditional 1:ethtool supports getting the rate and duplex settings for each slave

Conditional 2:switch (switch) supports IEEE 802.3ad Dynamic link aggregation

Condition 3: most switch (switches) require specific configuration to support 802.3ad mode

The sixth mode: mod=5, namely: (balance-tlb) Adaptive transmit load balancing (Adapter Transport load balancing)

Features: do not need any special switch (switch) support channel bonding. Outbound traffic is allocated on each slave based on the current load (based on speed). If the slave that is receiving data fails, another slave takes over the MAC address of the failed slave.

A necessary condition for this mode: ethtool supports getting the rate of each slave

The seventh mode: mod=6, namely: (balance-alb) Adaptive load balancing (Adapter Adaptive load balancing)

Features: this mode includes balance-tlb mode, plus receiving load balancing (receive load balance, rlb) for IPV4 traffic, and does not require any switch (switch) support. Receiving load balancing is implemented through ARP negotiation. The bonding driver intercepts the ARP reply sent by the local machine and rewrites the source hardware address to the unique hardware address of a slave in the bond, so that different peers use different hardware addresses to communicate.

Received traffic from the server side is also balanced. When the local ARP request is sent, the bonding driver copies and saves the IP information of the peer from the ARP package. When the ARP reply arrives from the peer, the bonding driver extracts its hardware address and initiates an ARP reply to a slave in the bond. One of the problems with using ARP negotiation for load balancing is that every time an ARP request is broadcast, the hardware address of bond is used, so after the peer learns this hardware address, all received traffic will flow to the current slave. This problem can be solved by sending updates (ARP replies) to all peers, which contain their unique hardware addresses, causing traffic to be redistributed. Received traffic is also redistributed when a new slave is added to the bond, or when an inactive slave is reactivated. The received load is sequentially distributed (round robin) on the fastest slave in the bond

When a link is reconnected, or a new slave is added to the bond, received traffic is redistributed across all currently active slave, and an ARP reply is initiated for each client using the specified MAC address. The updelay parameter described below must be set to a value greater than or equal to the switch (switch) forwarding delay to ensure that ARP replies sent to the peer will not be blocked by switch (switch).

Necessary conditions:

Conditional 1:ethtool supports getting the rate of each slave

Condition 2: the underlying driver supports setting the hardware address of a device, so that there is always a slave (curr_active_slave) using the hardware address of bond, while ensuring that the slave in each bond has a unique hardware address. If curr_active_slave fails, its hardware address will be taken over by the newly selected curr_active_slave

In fact, the difference between mod=6 and mod=0: mod=6, first full of eth0 traffic, and then occupy eth2, … EthX; and mod=0, you will find that the traffic of both ports is very stable, basically the same bandwidth. On the other hand, mod=6 will find that the first port has a high traffic flow, and the second port accounts for only a small part of the traffic.

Linux network port binding

Through the network port binding (bond) technology, it is easy to achieve network port redundancy and load balancing, so as to achieve the goal of high availability and high reliability. Premise agreement:

The two physical network ports are: eth0,eth2

The bound virtual port is: bond0

The server IP is: 192.168.0.100

First, configure the configuration file:

/ etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0

BOOTPROTO=none

ONBOOT=yes

IPADDR=192.168.0.100

NETMASK=255.255.255.0

NETWORK=192.168.0.0

BROADCAST=192.168.0.255

# BROADCAST broadcast address

/ etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

/ etc/sysconfig/network-scripts/ifcfg-eth2

DEVICE=eth2

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

The second step is to modify the modprobe related settings file and load the bonding module:

1. Here, we directly create a dedicated settings file / etc/modprobe.d/bonding.conf that loads bonding

[root@test ~] # vi / etc/modprobe.d/bonding.conf

# append

Alias bond0 bonding

Options bonding mode=0 miimon=200

two。 Load module (you don't have to load it manually after restarting the system)

[root@test ~] # modprobe bonding

3. Verify that the module is loaded successfully:

[root@test ~] # lsmod | grep bonding

Bonding 100065 0

Step 3, restart the network, and then confirm the situation:

[root@test ~] # / etc/init.d/network restart

[root@test ~] # cat / proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008)

Bonding Mode: fault-tolerance (active-backup)

Primary Slave: None

Currently Active Slave: eth0

……

[root@test ~] # ifconfig | grep HWaddr

Bond0 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74

Eth0 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74

Eth2 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74

From the confirmation message above, we can see three important messages:

1. The current bonding mode is active-backup

two。 Now the network port of Active status is eth0.

3. The physical address of bond0 eth0 is the same as that of eth0 in the state of bond0.This is to avoid confusion on the upper switch.

Unplug a network cable at will, and then access your server to see if the network is still open.

Step 4: the system starts automatic binding and adds a default gateway:

[root@test ~] # vi / etc/rc.d/rc.local

# append

Ifenslave bond0 eth0 eth2

Route add default gw 192.168.0.1

If you can access the Internet, there is no need to add routing, 0.1 address is modified according to the environment.

Note: the previous two network ports are only bound into a bond0. If we want to set multiple bond ports, such as physical network ports eth0 and eth2 to form bond0,eth3 and eth4 to form bond1

Then the setting method of the network port setting file is the same as that described in step 1 above, except that the setting of / etc/modprobe.d/bonding.conf cannot be simply superimposed as follows:

Alias bond0 bonding

Options bonding mode=1 miimon=200

Alias bond1 bonding

Options bonding mode=1 miimon=200

There are two ways to set up correctly:

First, as you can see, in this way, the mode of multiple bond ports can only be set to the same:

Alias bond0 bonding

Alias bond1 bonding

Options bonding max_bonds=2 miimon=200 mode=1

Second, in this way, the mode of different bond ports can be set to different:

Alias bond0 bonding

Options bond0 miimon=100 mode=1

Install bond1 / sbin/modprobe bonding-o bond1 miimon=200 mode=0

Take a closer look at the above two setting methods, now if you want to set 3, 4, or even more bond ports, you should also know it!

Postscript: briefly introduce the meaning of some parameters in options when loading the bonding module above:

Miimon monitors the frequency of network links in milliseconds, which we set to 200ms.

Number of bond ports configured by max_bonds

There are mainly the following mode bond modes. In general practical applications, 0 and 1 are used more often.

If you want to have an in-depth understanding of the characteristics of these models, it is up to the reader to look up the information and practice it.

Diagram of binding of multiple network cards

Log in with root user

Use the ifconfig command to look at the ip address to see if eth0 and eth2 have obtained the IP address (because linux is a server connected to a DHCP)

Check to see that the IP address is eth0 16.157.125.78 eth2 16.157.125.113

Broadcast: 16.157.125.255 mask: 255.255.254.0 (eth0 and eth2 are both this broadcast and mask)

Edit the virtual network interface configuration file and specify the network card IP

Vi / etc/sysconfig/ network-scripts/ ifcfg-bond0 creates a virtual network interface profile

, [root@rhas-13 root] # cp / etc/sysconfig/network-scripts/ifcfg-eth0 ifcfg-bond0 copy the configuration files in ifcfg-eth0 to ifcfg-bond0

Then use the vi ifcfg-bond0 command to modify the virtual configuration port.

, modify the first line DEVICE=bond0, and then change the configuration to the configuration of eth0 (the configuration is completed as shown in the following figure)

Click here to browse the picture in the new window

Use the cat command to check the configuration of eth0 and eth2

Click here to browse the picture in the new window

、 # vi / etc/modules.conf

Edit the / etc/modules.conf file and add the following line to make the system load the bonding module at startup

Click here to browse the picture in the new window

Add the following two lines

Alias bond0 bonding

Options bond0 miimon=100 mode=1

Description: miimon is used for link monitoring. For example: miimon=100, then the system monitors the link connection status once per 100ms, and if one line fails, it will be transferred to another line; the value of mode indicates the working mode, there are four modes: 0mem1,2prime3, and two are commonly used.

Mode=0 indicates that load balancing (round-robin) is a load balancing method, and both NICs work.

Mode=1 said that fault-tolerance (active-backup) provides redundancy and works in an active and standby mode, that is, 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 only the external link down of the switch is down and the switch itself is not down, then bonding will continue to use the link as if there is nothing wrong with it.

Click here to browse the picture in the new window

、 # vi / etc/rc.d/rc.local

Click here to browse the picture in the new window

, add two lines

Ifenslave bond0 eth0 eth2

Route add-net 16.157.125.255 netmask 255.255.255.0 bond0

After being added, the following figure is shown:

Click here to browse the picture in the new window

Reboot self-test when looking at the red box inside the success.

Click here to browse the picture in the new window

You can go into the system and check the ip.

Click here to browse the picture in the new window

The above figure shows that bond0 has obtained the address initialized by eth0, and the mac addresses of eth0 and eth2 are the same, indicating that the two blocks have been bound into a network card.

Source: http://www.cnblogs.com/archoncap/p/6079915.html

Error: Connection activation failed: The connection is not for this device.

Solution:

[root@niejicai] # chkconfig NetworkManager off

[root@niejicai] # chkconfig network on

[root@niejicai] # service NetworkManager stop

[root@niejicai] # service network start

This is the end of the introduction of "introduction to seven modes of binding dual network cards under Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report