Linux adopts dual network card bond and driver interface

  • 2020-12-16 06:16:35
  • OfStack

What is a bond

bond is a common technique used in production scenarios to realize the redundancy, bandwidth expansion and load balancing of local network cards by binding multiple network cards into one logical network card.

Applicable scenario

The two network cards of the server need to be bond, and the network card after bond needs to be configured with the addresses of different network segments for different traffic. At this time, the way of driver interface can be adopted.

The experimental scene

equipment

Server: Server_A Core switch: Switch_A, Switch_B

Switch connection mode: stack

Server network card: enp176s0f0, enp176s0f1 do bond

IP section division

The business section
201: VLAN 10.10.51.0/24 public
401: VLAN 111.20.200.88/27

requirements

The two core switches attached to server Server_A, Switch_A and Switch_B, are stacked. The optical ports of Server_A, enp176s0f0 and enp176s0f1, are respectively connected to Switch_A and Switch_B. Now we require enp176s0f0 and enp176s0f1 to do bond, address 10.10.51.16 for traffic, address 111.20.200.90 for public network traffic, switch port for binding ES75en-ES76en and pass-through VLAN201 and VLAN401.

Network card configuration script


#  stopped NetworkManager service 
systemctl stop NetworkManager.service 
systemctl disable NetworkManager.service

#  The backup 
cp /etc/sysconfig/network-scripts/ifcfg-enp176s0f0{,.bak}
cp /etc/sysconfig/network-scripts/ifcfg-enp176s0f1{,.bak}

#  Change the network card protocol none And the device does not boot from the boot, and do dual network card configuration 
sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=none/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f0
sed -i 's/ONBOOT=no/ONBOOT=yes/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f0
echo "MASTER=bond0" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f0
echo "SLAVE=yes" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f0

sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=none/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f1
sed -i 's/ONBOOT=no/ONBOOT=yes/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f1
echo "MASTER=bond0" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f1
echo "SLAVE=yes" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f1

#  The LAN bond0
echo "DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static" >/etc/sysconfig/network-scripts/ifcfg-bond0

#  Write the module file, bond Model for mode 0
echo "alias bond0 bonding
options bond0 miimon=100 mode=0" >/etc/modprobe.d/bond.conf
#  Load module 
modprobe bonding

#  Driver interface bond0.201
echo "DEVICE=bond0.201
TYPE=Vlan
PHYSDEV=bond0
ONBOOT=yes
BOOTPROTO=static
REORDER_HDR=yes
IPADDR=10.10.51.16
GATEWAY=10.10.51.1
NETMASK=255.255.255.0
DNS1=114.114.114.114
DNS2=8.8.8.8
VLAN=yes
VLAN_ID=201" >/etc/sysconfig/network-scripts/ifcfg-bond0.201

#  Driver interface bond0.401
echo "DEVICE=bond0.401
TYPE=Vlan
PHYSDEV=bond0
ONBOOT=yes
BOOTPROTO=static
REORDER_HDR=yes
IPADDR=111.20.200.90
GATEWAY=111.20.200.89
NETMASK=255.255.255.0
DNS1=114.114.114.114
DNS2=8.8.8.8
VLAN=yes
VLAN_ID=401" >/etc/sysconfig/network-scripts/ifcfg-bond0.401

#  Load the module and restart the host 
modprobe 8021q
reboot

The key point

Switch side if eth-trunk, then server side must driver interface

The switch side and the server side can either negotiate with lacp or can't afford either, otherwise the ports will be different

Switch side ES98en-ES99en port configuration example


[HH2B108-H01-2-HW9006X-SW001-Eth-Trunk12]display this 
#
interface Eth-Trunk12
port link-type trunk
port trunk allow-pass vlan 201 401
#
return

The lacp protocol on the server side uses bond pattern 4, as shown below


 # more /etc/modprobe.d/bond.conf
 alias bond0 bonding
 options bond0 miimon=100 mode=4 lacp_rate=1

The VLAN number 1 in the subinterface configuration file "DEVICE=bond0.401 "must remain 1 to the VLAN number that needs to be passed through

After configuring the subinterface 1 must restart the server to take effect!!

Conclusion:


Related articles: