CentOS8_网络基础(网卡bonding的配置)
笺注:这是在 CentOS8安装network服务 的基础上进行的。
先查看主机有哪些物理网卡可用:
[root@centos8 ~]# ifconfig -a
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.168.154 netmask 255.255.255.0 broadcast 192.168.168.255
inet6 fe80::92ab:5fb4:5373:ad53 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:cb:1e:40 txqueuelen 1000 (Ethernet)
RX packets 247 bytes 23358 (22.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 204 bytes 27899 (27.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens224: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.168.173 netmask 255.255.255.0 broadcast 192.168.168.255
inet6 fe80::e0e6:9a32:5efb:3c5d prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:cb:1e:4a txqueuelen 1000 (Ethernet)
RX packets 65 bytes 6283 (6.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 59 bytes 10325 (10.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
生产环境中,主机如果有两张网卡,网卡bonding的配置,一般建议采用主备模式(mode=1)
[root@centos8 ~]# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
TYPE=Bond
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.168.154
NETMASK=255.255.255.0
GATEWAY=192.168.168.2
DNS1=8.8.8.8
DNS2=114.114.114.114
USERCTL=no
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1"
[root@centos8 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens160
DEVICE=ens160
ONBOOT=yes
SLAVE=yes
USERCTL=no
BOOTPROTO=static
MASTER=bond0
[root@centos8 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens224
DEVICE=ens224
ONBOOT=yes
SLAVE=yes
USERCTL=no
BOOTPROTO=static
MASTER=bond0
还要重启网络服务:
[root@centos8 ~]# systemctl restart network.service
网卡bonding的配置成功:
[root@centos8 ~]# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 192.168.168.154 netmask 255.255.255.0 broadcast 192.168.168.255
inet6 fe80::20c:29ff:fecb:1e40 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:cb:1e:40 txqueuelen 1000 (Ethernet)
RX packets 17 bytes 1124 (1.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 844 (844.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens160: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 00:0c:29:cb:1e:40 txqueuelen 1000 (Ethernet)
RX packets 12 bytes 804 (804.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 844 (844.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens224: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 00:0c:29:cb:1e:4a txqueuelen 1000 (Ethernet)
RX packets 5 bytes 320 (320.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
笺注:服务器重启后,依旧生效的。
查看bond0接口的状态:
[root@centos8 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: None
Currently Active Slave: ens160 #可以看到网卡ens160处于活跃状态
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0
Slave Interface: ens160
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:cb:1e:40
Slave queue ID: 0
Slave Interface: ens224
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:cb:1e:4a
Slave queue ID: 0
######
测试两张网卡的自动切换
正常的话,当网卡ens160 down了之后,当前活跃的网卡会自动变为ens224
[root@centos8 ~]# ifdown ens160
WARN : [ifdown] You are using 'ifdown' script provided by 'network-scripts', which are now deprecated.
WARN : [ifdown] 'network-scripts' will be removed in one of the next major releases of RHEL.
WARN : [ifdown] It is advised to switch to 'NetworkManager' instead - it provides 'ifup/ifdown' scripts as well.
成功断开设备 "ens160"。
查看bond0接口的状态:
[root@centos8 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: None
Currently Active Slave: ens224 #可以看到网卡ens224处于活跃状态
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0
Slave Interface: ens224
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:cb:1e:4a
Slave queue ID: 0
备注:
只要还有一张网卡正常,主机的网络通讯都是正常的。
开启网卡ens160
[root@centos8 ~]# ifup ens160
WARN : [ifup] You are using 'ifup' script provided by 'network-scripts', which are now deprecated.
WARN : [ifup] 'network-scripts' will be removed in one of the next major releases of RHEL.
WARN : [ifup] It is advised to switch to 'NetworkManager' instead - it provides 'ifup/ifdown' scripts as well.
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/8)
[root@centos8 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: None
Currently Active Slave: ens224
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0
Slave Interface: ens224
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:cb:1e:4a
Slave queue ID: 0
Slave Interface: ens160
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:cb:1e:40
Slave queue ID: 0
相关文章:
CentOS8_网络基础
CentOS8安装KVM |