文档课题:Linux 7实现多网卡绑定—bond0方式.
系 统:centos 7.9 64位
环境介绍:vmware虚拟机+网卡为NAT模式.
说 明:此次演示bond0,bond地址192.168.133.120
1、添加网卡
添加2块网卡,加上此前网卡共3块网卡.
2、关闭networkmanager
--关闭networkmanager服务.
[root@liujun ~]# systemctl disable --now NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
Removed symlink /etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service.
说明:now表示立即关闭NetworkManager服务.
3、网卡配置文件
--修改网卡配置文件,注意网卡名需结合实际情况进行配置.
3.1、网卡原数据
[root@liujun ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:98:c5:5f brd ff:ff:ff:ff:ff:ff
inet 192.168.133.218/24 brd 192.168.133.255 scope global noprefixroute dynamic ens33
valid_lft 1038sec preferred_lft 1038sec
inet6 fe80::e107:1ed3:d4e5:f7ab/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:98:c5:69 brd ff:ff:ff:ff:ff:ff
inet 192.168.133.120/24 brd 192.168.133.255 scope global noprefixroute ens37
valid_lft forever preferred_lft forever
inet6 fe80::e007:4abd:58d:5da3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:98:c5:73 brd ff:ff:ff:ff:ff:ff
inet 192.168.133.217/24 brd 192.168.133.255 scope global noprefixroute dynamic ens38
valid_lft 1038sec preferred_lft 1038sec
inet6 fe80::46fe:1c1:a824:9da9/64 scope link noprefixroute
valid_lft forever preferred_lft forever
5: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:a8:7c:6f brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
6: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:a8:7c:6f brd ff:ff:ff:ff:ff:ff
[root@liujun network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@liujun network-scripts]# cat ifcfg-ens37
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens37
UUID=e7191296-fd65-478d-936e-f43dc98f1745
DEVICE=ens37
ONBOOT=yes
IPADDR=192.168.133.120
DNS1=192.168.133.2
GATEWAY=192.168.133.2
PREFIX=24
3.2、修改配置文件
3.2.1、ifcfg-ens37
[root@liujun network-scripts]# vi ifcfg-ens37
按如下修改:
DEVICE=ens37
NAME=ens37
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
[root@liujun network-scripts]# cp ifcfg-ens37 ifcfg-ens33
[root@liujun network-scripts]# cp ifcfg-ens37 ifcfg-ens38
3.2.2、ifcfg-ens33
[root@liujun network-scripts]# vi ifcfg-ens33
按如下修改:
DEVICE=ens33
NAME=ens33
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
3.2.3、ifcfg-ens38
[root@liujun network-scripts]# vi ifcfg-ens38
按如下修改:
DEVICE=ens38
NAME=ens38
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
3.3、配置bond0
[root@liujun network-scripts]# vi ifcfg-bond0
按如下修改
DEVICE=bond0
TYPE=bond0
BONDING_MASTER=yes
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.133.120
NETMASK=255.255.255.0
GATEWAY=192.168.133.2
BONDING_OPTS="mode=0 miimon=100"
BONDING_MASTER=yes
NM_CONTROLLED=no
--加载bond模块
[root@liujun network-scripts]# vi /etc/modprobe.d/bonding.conf
添加如下:
alias bond0 binding
options bond0 miimon=100 mode=0
--开启网卡混杂模式
[root@liujun ~]# chmod +x /etc/rc.local
[root@liujun ~]# vi /etc/rc.local
添加如下内容
ip link set ens33 promisc on
ip link set ens37 promisc on
ip link set ens38 promisc on
4、测试
4.1、移除1块网卡
--重启服务器后,移除其中1块网卡进行测试.
[root@liujun ~]# reboot
[root@liujun ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,PROMISC,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether 00:0c:29:98:c5:5f brd ff:ff:ff:ff:ff:ff
3: ens37: <BROADCAST,MULTICAST,PROMISC,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether 00:0c:29:98:c5:5f brd ff:ff:ff:ff:ff:ff
4: ens38: <BROADCAST,MULTICAST,PROMISC,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether 00:0c:29:98:c5:5f brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:0c:29:98:c5:5f brd ff:ff:ff:ff:ff:ff
inet 192.168.133.120/24 brd 192.168.133.255 scope global bond0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe98:c55f/64 scope link
valid_lft forever preferred_lft forever
6: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:a8:7c:6f brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
7: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:a8:7c:6f brd ff:ff:ff:ff:ff:ff
说明:如上显示三张网卡,现移除一块测试.
[root@liujun ~]# ip a标签:00,bond0,forever,192.168,网卡,lft,ff,Linux,brd From: https://blog.51cto.com/u_12991611/5950165
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,PROMISC,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether 00:0c:29:98:c5:5f brd ff:ff:ff:ff:ff:ff
4: ens38: <BROADCAST,MULTICAST,PROMISC,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether 00:0c:29:98:c5:5f brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:0c:29:98:c5:5f brd ff:ff:ff:ff:ff:ff
inet 192.168.133.120/24 brd 192.168.133.255 scope global bond0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe98:c55f/64 scope link
valid_lft forever preferred_lft forever
6: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:a8:7c:6f brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
7: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:a8:7c:6f brd ff:ff:ff:ff:ff:ff
说明:如上所示,只剩网卡ens33、ens38.
C:\Users\Administrator>ping 192.168.133.120
正在 Ping 192.168.133.120 具有 32 字节的数据:
来自 192.168.133.120 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.133.120 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.133.120 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.133.120 的回复: 字节=32 时间<1ms TTL=64
192.168.133.120 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
说明:移除其中一张网卡后,依然能ping通服务器.
4.2、移除2张网卡
--接下来在移除一张网卡做测试.
[root@liujun ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,PROMISC,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether 00:0c:29:98:c5:5f brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:0c:29:98:c5:5f brd ff:ff:ff:ff:ff:ff
inet 192.168.133.120/24 brd 192.168.133.255 scope global bond0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe98:c55f/64 scope link
valid_lft forever preferred_lft forever
6: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:a8:7c:6f brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
7: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:a8:7c:6f brd ff:ff:ff:ff:ff:ff
说明:如上所示,只剩网卡ens33.
C:\Users\Administrator>ping 192.168.133.120
正在 Ping 192.168.133.120 具有 32 字节的数据:
来自 192.168.133.120 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.133.120 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.133.120 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.133.120 的回复: 字节=32 时间<1ms TTL=64
192.168.133.120 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
说明:依然能ping通服务器,bond技术有多种,生产环境通常会用到bond4,需结合交换机,设置链路聚合功能.
参考网址:https://www.bilibili.com/video/BV1vD4y1U7db/?spm_id_from=333.337.search-card.all.click&vd_source=8c872e2fd1d99229b38a73ed6718b776