Linux 7双网卡绑定
May302019
linux 7通过nmtui工具可以很方便的进行双网卡绑定,不需要像之前版本那样繁琐的修改配置文件,并且可用在安装操作系统时直接配置,本文主要记录使用nmtui工具配置双网卡绑定的过程。
使用root用户执行nmtui命令,启动nmtui工具管理界面,和之前版本的setup工具相似。
[root@SL010A-IVDB01 ~]# nmtui
选择Add按钮,回车。
选择添加类型为Bond,即双网卡绑定。
最上部设置双网卡绑定的名字,中部模式选择Active Backup,然后选择Add按钮添加要绑定的网卡,回车。
这里选择网卡类型,因为要绑定的网卡是千兆以太网,所以这里选择Ethernet,回车。
这里设置要绑定网卡的名字,然后选择OK按钮,回车。
同上,再添加第二块网卡,选择OK按钮,回车。
添加完两块网卡,基本就是上图 这样,如果要在这个页面直接配置IP,选择Show按钮,回车。
然后填写IP地址和网关即可,这里没有填写MASK地址的选项栏,需要在配置IP地址的时候在IP的后面直接写上, 255.255.255.0是/24,例如192.168.100.98/24。然后选择OK按钮,回车。
回车后,返回初始界面,选择OK,回车结束配置即可。这样双网卡绑定就结束了。可以通过ifconfig命令查看到网卡的信息。
[root@SL010A-IVDB01 ~]# ifconfig bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500 inet 192.168.100.98 netmask 255.255.255.0 broadcast 192.168.100.255 inet6 fe80::224e:a422:6672:56e2 prefixlen 64 scopeid 0x20<link> ether 98:be:94:35:74:80 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 10 bytes 1180 (1.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eno1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500 ether 98:be:94:35:74:80 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 10 bytes 1180 (1.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eno2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500 ether 98:be:94:35:74:80 txqueuelen 1000 (Ethernet) 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 enp0s29f0u2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether 9a:be:94:35:f4:83 txqueuelen 1000 (Ethernet) RX packets 1077 bytes 70075 (68.4 KiB) 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 ens2f0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 ether 90:e2:ba:6a:66:c8 txqueuelen 1000 (Ethernet) 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 device memory 0xc0700000-c077ffff ens2f1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 ether 90:e2:ba:6a:66:c9 txqueuelen 1000 (Ethernet) 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 device memory 0xc0780000-c07fffff ens3f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.2.98 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::e5bf:ef44:c11b:ad0 prefixlen 64 scopeid 0x20<link> ether 90:e2:ba:8c:5c:e8 txqueuelen 1000 (Ethernet) RX packets 23158 bytes 1472551 (1.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3378 bytes 1419406 (1.3 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens3f1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 ether 90:e2:ba:8c:5c:e9 txqueuelen 1000 (Ethernet) 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 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 336 bytes 31332 (30.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 336 bytes 31332 (30.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:63:fe:75 txqueuelen 1000 (Ethernet) 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
可用通过查看/proc/net/bonding/bond0文件来查看双网卡绑定的状态。
[root@SL010A-IVDB01 ~]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eno1 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eno1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 98:be:94:35:74:80 Slave queue ID: 0 Slave Interface: eno2 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 98:be:94:35:74:82 Slave queue ID: 0
可以看到当前活跃的网卡是eno1,可用关闭/启动这个网卡来测试双网卡绑定是否成功。
[root@SL010A-IVDB01 ~]# nmcli connection down eno1 [root@SL010A-IVDB01 ~]# nmcli connection up eno1 [root@SL010A-IVDB01 ~]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eno2 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eno2 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 98:be:94:35:74:82 Slave queue ID: 0 Slave Interface: eno1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 98:be:94:35:74:80 Slave queue ID: 0
可以看到活跃网卡切换到了eno2网卡,可用使用其他机器ping绑定后的网卡的IP,进行连通性测试。如果网卡切换后,网络一直通,则配置完成。