Learn about Linux network card bonding to improve network performance and redundancy

2024.05.25


Author:didiplus
networkLinux
This article will take a deep dive into what network card bonding is, how it works, common bonding modes, and how to configure and manage network card bonding in Linux systems.

In modern IT infrastructure, network performance and reliability are critical. For many enterprises and individual users, ensuring high availability and redundancy of the network is one of the top priorities. Linux provides a powerful solution - Network Interface Card Bonding (NIC Bonding). This article will take a deep look at what network card bonding is, how it works, common bonding modes, and how to configure and manage network card bonding in Linux systems.

What is Network Card Binding?

Network card bonding is a technology that aggregates multiple network interfaces to create a logical network interface to increase network bandwidth and provide redundancy. In short, network card bonding allows multiple network cards to work at the same time, thereby increasing data transmission rates and providing failover capabilities when a network card fails.

How Network Card Binding Works

The core idea of ​​network card bonding is to virtualize multiple physical network cards into a single logical interface. In this way, multiple network cards can jointly process traffic and improve the overall network throughput. At the same time, when a network card fails, the system can automatically switch the traffic to other available network cards, thus achieving redundancy and high availability.

Common binding modes

There are seven network card bonding modes (0 to 6), namely bond0, bond1, bond2, bond3, bond4, bond5 and bond6, of which three are commonly used:

  • mode=0: load balancing mode, with automatic backup function, but requires support and configuration of the switch.
  • mode=1: Automatic backup mode. When one line is disconnected, other lines will automatically take over.
  • mode=6: load balancing mode, with automatic backup function, does not require switch support and configuration.

1.mode=0 (balanced load mode, Balance-rr)

This mode distributes network traffic among all bound network interfaces in a round-robin manner. It ensures that each network interface takes turns sending and receiving packets to achieve a load balancing effect.

Features:

  • Load balancing: By distributing traffic in a round-robin manner, load balancing of all bound interfaces can be achieved.
  • Redundancy: If one of the interfaces fails, traffic will automatically switch to other normal interfaces to ensure the reliability of network connection.
  • 性能提升:在支持的环境中,可以显著提升网络带宽和性能,因为流量同时在多个接口上传输。

Require:

  • Switch support: This mode requires the connected switch to support EtherChannel (such as Cisco) or similar technology, and corresponding configuration needs to be performed on the switch to achieve link aggregation.
  • Configuration complexity: Since it requires support and configuration from the switch, the setup is more complicated.

Applicable scene:

  • Environments that require high bandwidth and high availability, such as server clusters, data centers, etc.
  • The environment has advanced switch devices that support link aggregation technology.

2.mode=1 (Active-backup)

In this mode, only one network interface is active and the other interfaces are in standby mode. If the active interface fails, the standby interface will automatically take over to ensure the continuity of network connection.

Features:

  • High availability: The network connection is highly available through an automatic backup mechanism. If the active interface fails, the backup interface will take over immediately, minimizing network interruption time.
  • Single-link traffic: Only one interface is active at any point in time, so the total bandwidth is limited to the bandwidth of a single interface.
  • No switch required: No special support or configuration of switches is required, suitable for most network environments.

Require:

  • Simple configuration: No complicated switch configuration is required, only binding configuration needs to be performed on the host.

Applicable scene:

  • The bandwidth requirement is not high, but a high-reliability network environment is required, such as the management interface of the server or the network connection of key business applications.
  • There are no advanced switch devices in the network environment that support link aggregation.

3.mode=2 (XOR mode, Balance-xor)

In this mode, traffic distribution is performed based on the transmitted traffic information, such as the source and destination MAC addresses, IP addresses, etc. The physical interface that each data packet should use is determined by performing an exclusive OR (XOR) operation on this information.

Features:

  • Load balancing: can effectively distribute traffic among different interfaces to achieve load balancing.
  • Redundancy: If one interface fails, other interfaces can take over its traffic to ensure the stability and reliability of network connections.
  • Performance optimization: Flow-based distribution allows for more efficient network traffic management, especially when multiple connections are in progress simultaneously.

Require:

  • Switch configuration: The connected switch needs to support link aggregation technology (such as EtherChannel or LACP), and the corresponding configuration needs to be performed on the switch to support XOR mode.
  • Configuration complexity: Since configuration needs to be performed on the switch, the configuration is relatively complex compared to the mode that does not require switch support.

Applicable scene:

  • Scenarios where there are a large number of concurrent connections between multiple clients and servers, such as a Web server cluster.
  • High-bandwidth environments that require load balancing across different connections.

working principle:

  • The XOR mode performs an XOR operation on the source and destination address information of the data packet and uses the calculation result to select a physical interface to send the data packet.
  • This method ensures that traffic with the same pair of source and destination addresses is always transmitted through the same interface, thus avoiding the problem of out-of-order packets.

4.mode=3 (Broadcast mode)

In this mode, all outgoing data packets are broadcast through all network interfaces (that is, all interfaces send the same data packets). This ensures that the data packets are transmitted to the destination through all possible paths, thereby improving the reliability of data transmission.

Features:

  • Data redundancy: Each data packet is sent through all bound interfaces. Therefore, when any interface fails, other interfaces can continue to send data packets, ensuring the reliability of data transmission.
  • No load balancing: There is no load balancing function in this mode because all interfaces will send the same data packets at the same time and the bandwidth cannot be improved.
  • High reliability: Suitable for scenarios where you need to ensure that data packets reach their destination, because even if one interface fails, data packets can still be transmitted through other interfaces.

Require:

  • Support for multicast/broadcast: Connected network devices and the network structure need to support multicast or broadcast transmissions.
  • The configuration is relatively simple: no complicated switch configuration like mode=0 is required.

Applicable scene:

  • Environments that require extremely high reliability, such as real-time communication systems and financial transaction systems that need to ensure that data packets reach their destination.
  • Scenarios that do not require high bandwidth but require high data transmission success rate.

5.mode=4 (IEEE 802.3ad dynamic link aggregation)

mode=4 uses the IEEE 802.3ad standard to bundle multiple network interfaces through the dynamic link aggregation protocol (LACP, Link Aggregation Control Protocol). This mode allows multiple network cards to work together to increase bandwidth and provide redundancy.

Features:

  • Load balancing: Based on the LACP protocol, load balancing of multiple network interfaces can be achieved, improving the overall network throughput.
  • Redundancy: When a link fails, traffic will automatically switch to other normal links to ensure high availability of the network.
  • Dynamic configuration: The LACP protocol allows dynamic configuration and management of link aggregation, and the number of links can be adjusted according to actual conditions.
  • Bandwidth aggregation: The bandwidth of multiple network interfaces can be aggregated together to form a larger virtual bandwidth.

Require:

  • Switch support: The switch to be connected needs to support the LACP protocol of the IEEE 802.3ad standard and needs to be configured accordingly on the switch.
  • Configuration complexity: Since the LACP function of the switch needs to be configured, the setup is relatively complex.

Applicable scene:

  • Scenarios that require high bandwidth and high reliability, such as data centers and high-performance computing environments.
  • Enterprise-level network environments, especially those that require dynamic adjustment of network bandwidth and load.

6.mode=5 (Adapter Transmission Load Balancing, Balance-tlb)

This mode load balances multiple network interfaces by dynamically adjusting outbound traffic based on the current load on each interface. Incoming traffic is handled by the current primary interface.

Features:

  • Transmission load balancing: By monitoring the load of each interface, the traffic distribution is dynamically adjusted to balance the outbound traffic among the interfaces.
  • Automatic backup: If one interface fails, traffic will automatically switch to other interfaces to ensure the reliability of network connection.
  • No switch support required: This mode does not require the switch to support link aggregation technology, so the configuration is simple.

Require:

  • One-way load balancing: Only outbound traffic is load balanced, and inbound traffic is still handled by the primary interface.
  • Dynamic load adjustment: The system needs to support dynamic monitoring and adjustment of interface load.

Applicable scene:

  • For environments without advanced switch support.
  • Scenarios that require outbound traffic to be distributed across multiple interfaces, such as network servers and data transfer applications.

7.mode=6 (Balanced load mode, Balance-alb)

Mode=6 is a load balancing mode, also known as Adaptive Load Balancing (ALB). It is an improvement on mode=0, mainly targeting a problem in mode=0, namely MAC address storm. MAC address storm means that when a network card in mode=0 fails, its MAC address will be switched to another network card, causing all devices in the network to relearn new MAC addresses, resulting in temporary network congestion. Mode=6 solves this problem by dynamically modifying the MAC address of the network card.

Features:

  • Load balancing: Similar to mode=0, network traffic is distributed among all bound network interfaces in a round-robin manner to achieve load balancing.
  • Redundancy: When an interface fails, other normal interfaces will take over its MAC address and IP address without the support of a switch.
  • Dynamic modification of MAC address: To avoid MAC address storms, mode=6 will dynamically modify the MAC address of the network card to reduce network interruptions.

Require:

  • No need for switch support: Compared with mode=0, mode=6 does not require switch support and configuration, reducing deployment complexity.
  • Compatibility: It is necessary to ensure the compatibility of network devices with dynamic MAC address changes.

Applicable scene:

  • Environments that require high availability and load balancing and do not want to rely on switch configuration.
  • Scenarios with strict requirements on network interruption time, such as online trading systems and cloud services.

8. Summary

For your convenience, the above is summarized in the following table:

Configuration Example

In Ubuntu system, you can configure the bond mode of different network cards by editing the file under /etc/netplan/01-network-manager-all.yaml. The following takes mode=4 as an example:

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      optional: true
    eth1:
      dhcp4: no
      optional: true
  bonds:
    bond4:  
      dhcp4: no
      addresses:
        - 192.168.1.103/24
      nameservers:
        addresses:
          - 192.168.1.1
          - 114.114.114.114
      routes:
          - to: default
            via: 192.168.1.1
      interfaces:
        - eth0
        - eth1
      parameters:
        mode: 802.3ad  #这里是指定bond的模式
        mii-monitor-interval: 100
        lacp-rate: fast
        transmit-hash-policy: layer2
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.

Modify the above configuration file, restart the network service, and check whether it takes effect by executing the following command:

For detailed information, see the file /proc/net/bonding/bond4, as shown below:

On the switch, you need to enable LACP and add the corresponding ports to the LACP group. For example, on a Cisco switch, you can configure it with the following command:

Switch(config)# interface range GigabitEthernet0/1 - 2
Switch(config-if-range)# channel-group 1 mode active
Switch(config-if-range)# exit
Switch(config)# interface Port-channel 1
Switch(config-if)# switchport mode trunk
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

This configuration bonds the eth0 and eth1 interfaces into bond0 and sets it to mode=4. The configuration example on the switch shows how to enable LACP and join the ports to the aggregation group. It should be noted that the specific configuration may vary depending on the system and device.

Summary Network card binding is an important technology to improve the network performance and reliability of Linux systems. By binding multiple network cards together, users can achieve higher bandwidth, better load balancing, and stronger redundancy. Different binding modes are suitable for different application scenarios, and users can choose the appropriate mode for configuration according to actual needs. Mastering network card binding technology can not only improve the network performance of the system, but also provide higher stability and reliability for key business applications.