centos7. 6. Make bond with network card

Time:2022-5-25

Experimental environment: CentOS 7 6. Network card ens1, ens2

Bond type description:

There are seven (0 ~ 6) network card binding modes: bond0, bond1, bond2, bond3, bond4, bond5 and bond6

There are four commonly used

  • Mode = 0: (balance RR) round robin policy: load balancing mode, with automatic backup, but it needs “switch” support and setting.
  • Mode = 1, (active backup) active backup policy only one device is active. When one device goes down, the other will be converted from backup to primary device immediately. The MAC address is externally visible. From the outside, the MAC address of bond is unique.
  • Mode = 5, (balance TLB) adaptive transmit load balancing does not require any special channel bonding supported by the switch.
  • Mode = 6, (balance ALB) adaptive load balancing this mode includes the balance TLB mode, plus receive load balance (RLB) for IPv4 traffic, and does not need any switch support. Receiving load balancing is realized through ARP negotiation

Method 1: modify the configuration file to make bond0 (confirmed to be valid)

  • 1. Create bond0 profile
[[email protected] sysconfig]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
TYPE=Ethernet
IPADDR=192.168.1.3
GATEWAY=192.168.1.1
PREFIX=24
IPV6INIT=no
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
BONDING_OPTS="mode=1"
DNS1=199.29.29.29
NDS2=223.5.5.5
  • 2. Modify network card EM1 and em2 configuration files
[[email protected] sysconfig]# cat /etc/sysconfig/network-scripts/ifcfg-em1
DEVICE=em1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0          
SLAVE=yes
IPV6INIT=no

[[email protected] sysconfig]# cat /etc/sysconfig/network-scripts/ifcfg-em2
DEVICE=em2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0          
SLAVE=yes
IPV6INIT=no
  • 3. Restart the network
systemctl restart network
  • 4. Detection
[[email protected] sysconfig]# cat /proc/net/bonding/bond0 

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: em2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 18:66:da:4d:c3:e8
Slave queue ID: 0

Slave Interface: em1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 18:66:da:4d:c3:e7
Slave queue ID: 0

#######################I am the dividing line#######################

Method 2: use the nmcli command to do bond1

Network cards eth0 and eth1 do bond1

  • 1. Add bond
nmcli connection add type bond con-name bond0 ifname bond0 mode active-backup ip4 172.25.254.136/24 
  • 2. Monitor bond changes and network status (open a new terminal)

watch -n 1 cat /proc/net/bonding/bond0

  • 3. Bind two network cards to bond respectively:
nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0

nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0
  • 4. Observe bond reaction and network changes by stopping one of the network cards
Ifconfig eth0 down # stop eth0
 Nmcli connection delete eth0 # unbind eth0 from bond
 Nmcli connection add con name eth0 ifname eth0 type bond slave master bond0 # plus eth0
 Ifconfig eth1 down # stop eth1

#######################I am the dividing line#######################

Method 3: use nmcli command to make team (confirmed to be effective)

  • 1. Set binding mode loadbalance
nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name":"loadbalance"}}' 
  • 2. Set the IP, mask, gateway and manual mode of team0
nmcli con modify team0 ipv4.addresses '10.2.5.117/24' ipv4.gateway '10.2.5.254' ipv4.method manual
  • 3. Add EM1 and em2 to team0 group respectively
nmcli con add type team-slave con-name team0-port1 ifname em1 master team0
nmcli con add type team-slave con-name team0-port2 ifname em2 master team0
  • 4. Check the network card information. If orange one is found, start it
nmcli con sh

*5. If orange is found, start it

nmcli con up team0
  • 6. Restart the network
systemctl restart network
  • 7. Make sure the service is active
systemctl status network
systemctl status NetworkManager
  • 8. Viewing the binding result of teaming
teamdctl team0 st
ethtool team0

Difference between team and bond

Team can be understood as the upgrade of bond