Foreword:
In production, I received an alarm from the supervisor, and the network card of a server was switched back and forth, asking if it was abnormal. The reason is that when the server was in the test area, the dual network card mode was active-active, and it switched back and forth after it was in the production environment. This article simulates dual network card configuration and testing in an esxi environment.
Environmental description:
CPU name | Operating system version | ip | ESXi version | Remarks |
---|---|---|---|---|
client | Centos 7.6.1810 | 172.27.34.85 | 6.5.0 | Dual network card test host |
1. Construct a dual network card test environment
The system currently has only one network card, and a dual network card environment needs to be constructed.
1. View the existing environment
Network card ifcfg-ens160 configuration:
[root@client network-scripts]# more ifcfg-ens160
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
NAME=ens160
UUID=003981c1-76e4-4a67-9f84-f42cb033bbba
DEVICE=ens160
ONBOOT=yes
IPADDR=172.27.34.85
PREFIX=24
GATEWAY=172.27.34.1
IPV6_PRIVACY=no
DNS1=202.xxx.xxx.xxx
DNS fill in according to the actual situation
2. Add a new network card
The existing environment has only one network card
Add a network card
3. View the newly added network card
Two, dual network card configuration
1. New ifcfg-bond0
[root@client network-scripts]# touch ifcfg-bond0
[root@client network-scripts]# more ifcfg-bond0
TYPE=Bond
BOOTPROTO=static
DEFROUTE=yes
DEVICE=bond0
USERCTL=no
ONBOOT=yes
IPADDR=172.27.34.85
PREFIX=24
GATEWAY=172.27.34.1
DNS1=202.xxx.xxx.xxx
BONDING_OPTS="miimon=100 mode=1"
Create a new network card file ifcfg-bond0 and configure it. mode=1: active/standby mode, only one network card works, when the main network card fails, it will switch to the standby network card; mode=0: load balancing mode, both network cards work, providing twice the bandwidth. The network card mode can be selected according to the actual production situation.
2. Configure the network card ifcfg-ens160
[root@client network-scripts]# more ifcfg-ens160
TYPE=Ethernet
BOOTPROTO=static
NAME=eno2
HWADDR=00:0c:29:c8:de:24
DEVICE=ens160
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
3. Configure ifcfg-ens190
[root@client network-scripts]# touch ifcfg-ens190
[root@client network-scripts]# more ifcfg-ens190
TYPE=Ethernet
BOOTPROTO=static
NAME=eno2
HWADDR=00:0c:29:c8:de:2e
DEVICE=ens190
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
Create a new network card file ifcfg-ens190 and configure
4. Restart the network
[root@client ~]# systemctl restart network
Restart network or host
5. View the network
NIC bond0 has been tied to ip 172.27.34.85
Three, dual network card switch test
1. View the main network port
[root@client ~]# cat /proc/net/bonding/bond0
Dual network card mode is active and standby, the main network card is ens160
2. Turn off ens160
[root@client ~]# ifdown ifcfg-ens160
成功断开设备 'ens160'。
[root@client ~]# cat /proc/net/bonding/bond0
At this time, the main network card is ens190, and the network connection is normal
3. Start ens160
[root@client ~]# ifup ifcfg-ens160
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/11)
[root@client ~]# cat /proc/net/bonding/bond0
Start ens160, the main network card is still ens190, and the network connection is normal
The test is complete, and the dual network card active/standby mode is valid.
All scripts and configuration files in this article have been uploaded to github: Centos7.6-for-Dual-network-card-settings