linux网卡链路聚合

时间:2024-03-28 17:47:47

1. 网卡的链路聚合
网卡的链路聚合就是将多块网卡连起来,当一块出现故障时网络依旧可以正常运行,可以有效的防止因为网卡损坏带来的损失,同时也可以提高网络访问速度。
支持模式有:
广播( broadcast ) - 容错。所有封包都通过所有Slave 接口广播
轮询( roundrobin ) - 轮询模式是两块网卡轮流使用。。
主备( activebackup )容错。主备模式是使用一块网卡,这块网卡坏了使用另一块网卡。
网卡的链路聚合一般常用的有**"bond"和"team"两种模式**,
"bond"模式最多可以添加两块网卡,
"team"模式最多可以添加八块网卡。

2、bond模式

环境设置:需要存在两块网卡设备,并且清除原有的网络连接。
1 清除网络连接
linux网卡链路聚合
linux网卡链路聚合

nmcli connection add con-name bond0
 ifname bond0 type bond mode active-backup ip4 172.25.47.111/24
 表示添加一个bond,名称为bond0,工作模式为主备,IP为 172.25.47.111/24。

linux网卡链路聚合

watch -n 1 cat /proc/net/bonding/bond0  查看bond0接口信息,并进行监控

目前看到没有网卡信息
linux网卡链路聚合

nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0
加第一个真实存在的网卡设备eth0到bond0接口

linux网卡链路聚合
linux网卡链路聚合

nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0
添加第二个真实存在的网卡设备eth1到bond0接口

linux网卡链路聚合
ping 172.25.254.2
进行 网络检测,当添加完成设备之后,网络可以使用。

由于采用的是主备模式:当一块网卡作为主网卡进行工作时,另外一个作为备用,一旦主网卡异常停止工作,备用网卡接替成为主网卡,保证网络不间断。
采用ifconfig eth0 down 以及 ifconfig eth up 来关闭以及开启网卡进行模拟。
linux网卡链路聚合

如果要删除该bond0聚合链路,依次删除:bond0 、eth0 、eth1 即可
nmcli connection delete bond0
nmcli connection delete eth0
nmcli connection delete eth1
linux网卡链路聚合
*

3、team模式

环境设置:清除原有的网络连接,team最多使用8块网卡,实验使用两块进行说明
linux网卡链路聚合

nmcli connection add con-name team0 ifname team0 type team config '{"runner":{"name":"activebackup"}}' ip4 172.25.47.111/24
表示建立一个team,名称为team0,工作模式为主备,IP为172.25.47.111/24

linux网卡链路聚合
linux网卡链路聚合
teamdctl team0 state # 查看team0接口信息
watch -n 1 teamdctl team0 state# 对team0接口信息集进行监控
linux网卡链路聚合

 nmcli connection add con-name eth0 ifname eth0 type team-slave master team0
 添加第一个真实存在的网卡设备eth0到team0接口

linux网卡链路聚合

nmcli connection add con-name eth1 ifname eth1 type team-slave master team0
添加第二个真实存在的网卡设备eth1到team0接口

测试 ping 172.25.254.2
由于采用的是主备模式:当一块网卡作为主网卡进行工作时,另外一个作为备用,一旦主网卡异常停止工作,备用网卡接替成为主网卡,保证网络不间断。
采用ifconfig eth0 down 以及 ifconfig eth up 来关闭以及开启网卡进行模拟。
linux网卡链路聚合
linux网卡链路聚合
如果要删除该bond0聚合链路,依次删除:bond0 、eth0 、eth1 即可
nmcli connection delete bond0
nmcli connection delete eth0
nmcli connection delete eth1