Basic knowledge of network card binding in Linux

Posted by jacksonpt on Sat, 01 Jan 2022 01:32:30 +0100

1. Introduction

The Linux network card binder provides a method to aggregate multiple network interfaces into a single logical interface. The behavior of the logical interface depends on the mode. Generally speaking, different modes provide hot standby or load balancing services respectively.

2. Configure bond binding

2.1 general

You can configure the network binding using the network initialization script of the distribution, or you can manually configure the network binding using iproute2 or sysfs interface. Distributions typically use one of three packages to initialize the network: initscripts, sysconfig, or interfaces. Iproute2 is mostly used for SuSE 8; Bond configuration can only be performed using the sysfs interface after installing the sysfs file system; Sysconfig is mostly used for SuSE 9; Initscripts are mostly used for Red Hat; Interfaces are mostly used in Debian. If you really don't know what kind of bond the operating system can use, you can try the following methods:
First, look for the file named interfaces in the / etc/network directory. If this file exists in the system, the system uses interfaces.
Otherwise, test the following command:

$ rpm -qf /sbin/ifup

Its response is a line of text beginning with "initscripts" or "sysconfig", followed by some numbers. This is a software package that provides network initialization scripts.

2.2 common bond configurations

This section is applicable to distributions with initscripts package that support network card binding, such as Red Hat Enterprise Linux 3 or later, Fedora, etc. On these systems, network initialization scripts can be configured to bind control devices.
In Enterprise Linux, the system will not automatically load the network card driver unless the ethX device is configured with an IP address. Due to this limitation, users must manually configure the network script file for all physical network cards of bondX members. The network script file is located in the following directory:

/etc/sysconfig/network-scripts

The file name must be prefixed with "ifcfg eth" and suffixed with the physical network card number of the network card. For example, the script name of eth0 is / etc / sysconfig / network scripts / ifcfg-eth0. Put the following text into the file:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

The "DEVICE =" line of each ethX DEVICE is different and must correspond to the file name, that is, the corresponding line of ifcfg-eth1 must be "DEVICE=eth1". The setting of the "MASTER =" line depends on the binding interface name. Like other network devices, they usually start from 0, and each DEVICE moves up one, that is, the first binding instance is bond0, the second is bond1, and so on.
Next, create a binding network script. The file name of this script is / etc / sysconfig / network scripts / ifcfg bondx, where X is the binding number. For bond0, the file name is "ifcfg-bond0", for bond1, the file name is "ifcfg-bond1", and so on. In this file, write the following text:

# vi /etc/sysconfig/network-scripts/ifcfg-bondX
DEVICE=bond0
IPADDR=192.168.1.1
NETMASK=255.255.255.0
NETWORK=192.168.1.0
BROADCAST=192.168.1.255
ONBOOT=yes
BOOTPROTO=none
USERCTL=no

Change specific lines (IPADDR, NETMASK, NETWORK, and BROADCAST) to match your NETWORK configuration.
Finally, edit / etc / modules Conf (or modprobe.conf) to load the binding module when using the bond0 interface:

# vi /etc/modprobe.conf
alias bond0 bonding
options bond0 mode=balance-alb miimon=100

For CentOS/RHEL 5, set the binding mode in the file / etc / sysconfig / network scripts / ifcfg-bond0 instead of in the file / etc / modprobe Conf, for example:

BONDING_OPTS="mode=active-backup arp_interval=60 arp_ip_target=192.168.1.254"

For CentOS/RHEL 6, in the directory / etc / modprobe D /, create a file named / etc / modprobe d/bonding. The new file of conf is "alias bond0 binding". You can also set the binding mode in the file / etc/sysconfig/networkscripts/ifcfg-bond0 instead of / etc / modprobe d/bonding. Conf.
Through bonding_ There is no need to edit / etc / modprobe. When setting options for opts d/*. conf.
For the / etc/sysconfig/network scripts/ifcfg-bond0 file, replace the sample parameters with the appropriate configuration. Finally, run "/ etc/rc.d/init.d/network restart" or "service network restart" as root to restart the network. The bond connection should be started now.

2.3 BONDING_ Description of opts options

    miimon:
Specifies the MII link monitoring frequency in milliseconds. This parameter determines the inspection frequency of the slave node link status to check whether the slave node has link failure. A value of zero disables MII link monitoring. Setting this value to 100 is a good choice.

    mode:
Specify a binding policy. The default value is balance RR (loop), that is, bond0. There are abundant information on these seven bond types on the network, so we won't repeat them.

3. Modify bond configuration

Each bond can be configured individually by manipulating the file located in / sys / class / net / < bond name > / bonding.
Example:
Configure the balance ALB mode for bond0:

# ifconfig bond0 down
# echo 6 > /sys/class/net/bond0/bonding/mode
 - or -
# echo balance-alb > /sys/class/net/bond0/bonding/mode
 Note: it must be closed first bond Interface before you can change the mode.

 
Enable MII monitoring on bond0 at 1 second intervals:

# echo 1000 > /sys/class/net/bond0/bonding/miimon
 Note: if enabled ARP Monitor, then enable MII Will be disabled during monitoring ARP Monitoring and vice versa.

4. Query bond configuration

4.1 query bond status

Each binding device has a read-only file in the / proc / net / binding directory. The contents of the file include binding configuration, options, and status information of each slave device.
For example, after loading the driver with parameters of mode=0 and miimon=1000, the contents of / proc/net/bonding/bond0 are generally as follows:

# cat /proc/net/bonding
Ethernet Channel Bonding Driver: 2.6.1 (October 29, 2004)
Bonding Mode: load balancing (round-robin)
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 1000
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth1
MII Status: up
Link Failure Count: 1

Slave Interface: eth0
MII Status: up
Link Failure Count: 1

The specific format and content will change according to the binding configuration, status and binding driven version.

4.2 query network conditions

You can use the ifconfig command to check the network configuration. The bond device is marked with MASTER and the SLAVE device is marked with SLAVE. The output of ifconfig does not contain the specific association information of the MASTER and SLAVE devices.
In the following example, bond0 interface is the master, while eth0 and eth1 are SLAVE. Note that all slaves of bond0 have the same MAC address as bond0 in other modes except TLB and ALB modes, which require each SLAVE to have a unique MAC address.

# /sbin/ifconfig
bond0     Link encap:Ethernet  HWaddr 00:C0:F0:1F:37:B4
          inet addr:XXX.XXX.XXX.YYY  Bcast:XXX.XXX.XXX.255  Mask:255.255.252.0
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:7224794 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3286647 errors:1 dropped:0 overruns:1 carrier:0
          collisions:0 txqueuelen:0

eth0      Link encap:Ethernet  HWaddr 00:C0:F0:1F:37:B4
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:3573025 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1643167 errors:1 dropped:0 overruns:1 carrier:0
          collisions:0 txqueuelen:100
          Interrupt:10 Base address:0x1080

eth1      Link encap:Ethernet  HWaddr 00:C0:F0:1F:37:B4
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:3651769 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1643480 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          Interrupt:9 Base address:0x1400

5. Switch configuration requirements

The active backup, balance TLB, and balance ALB modes (i.e., bond1, bond5, and bond6 modes) do not require any specific configuration of the switch.
Balance RR, balance XOR, and broadcast modes (i.e., bond0, bond2, bond3 modes) usually require switches to aggregate appropriate port packets together.

Reference documents

[1]Thomas Davis. Linux Ethernet Bonding Driver HOWTO[EB/OL]. [2006-04-24]. https://www.kernel.org/doc/Documentation/networking/bonding.txt.
[2]The Geek Diary. Basics of Ethernet Bonding in Linux[EB/OL]. [2021-01-01]. https://www.thegeekdiary.com/basics-of-ethernet-bonding-in-linux/.

Topics: Linux CentOS