In order to provide high availability of the network, we may need to bind multiple network cards into a virtual network card to provide external services, so that even if one of the physical network cards fails, it will not cause the connection to be interrupted. There are two ways to implement dual network card bonding: bond and team Bond supported modes A total of seven bond modes are supported [0-6], and three of them are commonly used, as follows:
As for the other modes, the explanations are as follows: mode=2: Select the serial number of the network card = (source MAC address XOR target MAC address) % the number of slave network cards. Other transmission strategies can be specified through the xmit_hash_policy configuration item. 1. Support using ethtool to obtain the speed and duplex settings of each slave network card; Configuring Bond
Note: The IP address is configured on bond1, and the physical network card does not need to be configured with an IP address #Load the bonding module and confirm that it has been loaded [root@web01 ~]# modprobe --first-time bonding [root@web01 ~]# lsmod | grep bonding bonding 141566 0 #Edit bond1 configuration file [root@web01 ~]# cat > /etc/sysconfig/network-scripts/ifcfg-bond1 << EOF > DEVICE=bond1 > TYPE=Bond >IPADDR=192.168.171.111 > NETMASK=255.255.255.0 > GATEWAY==192.168.171.2 > DNS1=114.114.114.114 > DNS2=8.8.8.8 > USERCTL=no > BOOTPROTO=none >ONBOOT=yes > EOF #Modify ens33 configuration file [root@web01 ~]# cat > /etc/sysconfig/network-scripts/ifcfg-ens33 << EOF > DEVICE=ens33 > TYPE=Ethernet >ONBOOT=yes > BOOTPROTO=none > DEFROUTE=yes > IPV4_FAILURE_FATAL=no > NMAE=ens33 > MASTER=bond1 # Need to be consistent with the DEVICE value in the ifcfg-bond0 configuration file above > SLAVE=yes > EOF #Modify ens36 configuration file [root@web01 ~]# cat > /etc/sysconfig/network-scripts/ifcfg-ens33 << EOF > DEVICE=ens36 > TYPE=Ethernet >ONBOOT=yes > BOOTPROTO=none > DEFROUTE=yes > IPV4_FAILURE_FATAL=no > NAME=ens36 > MASTER=bood1 > SLAVE=yes > EOF # Configuring bonding [root@web01 ~]# cat >> /etc/modules-load.d/bonding.conf << EOF > alias bond1 bonding > options bonding mode=1 miimon=200 # Load the bonding module, and the external virtual network interface device is bond1 > EOF #Restart the network card to make the configuration take effect[root@web01 ~]# systemctl restart network Note: If the network card service fails to start after the configuration is complete and no errors are found in the log, you can try closing NetworkManager and restarting the network card again. After restarting the network, check the information of each network card [root@web01 ~]# ip a show ens33 2: ens33: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond1 state UP group default qlen 1000 link/ether 00:0c:29:9f:33:9f brd ff:ff:ff:ff:ff:ff [root@web01 ~]# ip a show ens36 3: ens36: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond1 state UP group default qlen 1000 link/ether 00:0c:29:9f:33:9f brd ff:ff:ff:ff:ff:ff [root@web01 ~]# ip a show bond1 7: bond1: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 00:0c:29:9f:33:9f brd ff:ff:ff:ff:ff:ff inet 192.168.171.111/24 brd 192.168.171.255 scope global noprefixroute bond1 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe9f:339f/64 scope link valid_lft forever preferred_lft forever View bond1 related information # View the interface status of bond1 [root@web01 ~]# cat /proc/net/bonding/bond1 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: load balancing (round-robin) # Bonding mode MII Status: up # Interface status MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: ens33 # Backup interface: ens33 MII Status: up # Interface status Speed: 1000 Mbps # Port rate Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:9f:33:9f # Interface permanent MAC address Slave queue ID: 0 Slave Interface: ens36 # Backup interface: ens36 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:9f:33:a9 Slave queue ID: 0 When this step is achieved, if any network card in ens33 or ens36 is down, it will not affect communication Note: If you are using a vmware workstaction virtual machine for testing, please do not directly execute the command ifdown ens33 or ifdown ens36 for testing. In this way, the test will not work because of the virtual machine. You can cancel the connection in the network adapter. This is the end of this article about the sample code of using bond in linux to bind dual network cards to a single IP. For more information about how to bind dual network cards to a single IP in linux, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Implementation of clicking through the transparent area of irregular forms in Electron
>>: In-depth analysis of why MySQL does not recommend using uuid or snowflake id as primary key
zabbix_agent deployment: Recommendation: zabbix_a...
Table of contents Preface 1. MySQL enables SSL co...
Preface In actual business, paging is a common bu...
join() method: connects all elements in an array ...
I recently read Yahoo's 34 Golden Rules and le...
Recently, a service has an alarm, which has made ...
<br />Sometimes you may be asked questions l...
In the horizontal direction, you can set the cell...
This article introduces a framework made by Frame...
This article mainly explains tables, which are no...
The isnull() function cannot be used as a substit...
Table of contents Overview 1. Simple Example 1. U...
Table of contents 1. JS Object DOM –1, Function –...
Preface When making a page, we often encounter co...
Table of contents Background 1. What is dns-prefe...