linux几种链路聚合模式,使用nmcli配置主备模式链路聚合

本文档详细介绍了如何在CentOS7系统中使用nmtui命令行工具配置主备模式的链路聚合,通过将enp0s3和enp0s8两个网卡作为team0接口的slave接口,实现了网络连接的冗余备份。在配置过程中,首先创建Team接口,然后添加slave接口,并分配静态IP地址。最后,通过断开其中一个网卡接口验证主备模式的切换功能,确保在接口故障时能自动切换到备用接口,保持网络连接的稳定性。
摘要由CSDN通过智能技术生成

主备模式的链路聚合将其中一个接口置于备份状态,并且仅当活动接口断开链接时才会使其处于活动状态。

现在让我们在CentOS7中配置网卡绑定,运行ip link命令查看可以使用的网卡

[root@localhost ~]# ip link

1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: enp0s3: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000

link/ether 08:00:27:7b:d3:32 brd ff:ff:ff:ff:ff:ff

3: enp0s8: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000

link/ether 08:00:27:81:d3:be brd ff:ff:ff:ff:ff:ff

413c2d9c9d08af90622d6faae8424478.png

在这里使用enp0s3和enp0s8两个网卡配置 主备模式的链路聚合。

创建Team接口

[root@localhost ~]# nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}'

Connection 'team0' (4df78635-b9fc-4539-ab02-27db11c656fe) successfully added.

67f9a0f9c3fcd7352691e6377dd290a8.png

运行nmcli con show查看team0的配置

[root@localhost ~]# nmcli con show

NAME UUID TYPE DEVICE

team0 4df78635-b9fc-4539-ab02-27db11c656fe team team0

enp0s3 5005942f-a7fd-4e55-b8e7-77928d8da72d ethernet enp0s3

Wired connection 1 45dee64a-53b3-3e2a-b2d4-e377f3e668a2 ethernet enp0s8

dfa52ca3dca0c1aea332be153111e469.png

添加Slave接口

在这里使用enp0s3和enp0s8两个网卡作为team0的slave接口:

[root@localhost ~]# nmcli connection add type team-slave con-name team0-port1 ifname enp0s3 master team0

Connection 'team0-port1' (15183c4a-2053-4b53-ad58-de5a07ae3ae9) successfully added.

[root@localhost ~]# nmcli connection add type team-slave con-name team0-port2 ifname enp0s8 master team0

Connection 'team0-port2' (a34e20b0-3422-46e5-a947-bb2eaa6c0622) successfully added.

685c95358f9765435adabd396f06e924.png

查看端口配置信息:

[root@localhost ~]# nmcli connection show

NAME UUID TYPE DEVICE

team0 4df78635-b9fc-4539-ab02-27db11c656fe team team0

enp0s3 5005942f-a7fd-4e55-b8e7-77928d8da72d ethernet enp0s3

Wired connection 1 45dee64a-53b3-3e2a-b2d4-e377f3e668a2 ethernet enp0s8

team0-port1 15183c4a-2053-4b53-ad58-de5a07ae3ae9 ethernet --

team0-port2 a34e20b0-3422-46e5-a947-bb2eaa6c0622 ethernet --

f49eb7d076593a53a66528c04d9ce41b.png

分配IP地址

给team0分配一个静态的IP地址并启动team0配置:

[root@localhost ~]# nmcli connection modify team0 ipv4.method manual ipv4.addresses 192.168.0.200/24 ipv4.gateway 192.168.0.1 ipv4.dns 202.102.128.68

[root@localhost ~]# nmcli connection up team0

Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)

查看连接配置信息,发现team0-port1没有绑定在enp0s3这个网卡接口上

[root@localhost ~]# nmcli connection

23e77cade7331af7b9bcaeccc8dfcbd6.png

这是以内ifcfg-team0-port1配置文件和ifcfg-enp0s3两个配置文件都设置为开机启动了

dd8e4ef5d407c720d5c69bd1c29eb27d.png

所以我们需要关闭enp0s3的开机启动,在这里我们把enp0s3和Wired connection 1这两个配置都关掉开机启动

[root@localhost ~]# nmcli connection modify enp0s3 autoconnect no

[root@localhost ~]# nmcli connection modify Wired\ connection\ 1 autoconnect no

34a639165b64f7fceabf14481f56255d.png

然后重启一下网络服务,查看链接配置:

[root@localhost ~]# systemctl restart network

[root@localhost ~]# nmcli connection

[root@localhost ~]# ip ad

可以看到team0-port1和team0-port2都绑定在对应的网卡上面了,team0的ip地址显示的是手动设置的192.168.0.200

79373747ff1f5d42af4b5a777075759e.png

验证

查看team0的状态:

[root@localhost ~]# teamdctl team0 state

setup:

runner: activebackup

ports:

enp0s3

link watches:

link summary: up

instance[link_watch_0]:

name: ethtool

link: up

down count: 0

enp0s8

link watches:

link summary: up

instance[link_watch_0]:

name: ethtool

link: up

down count: 0

runner:

active port: enp0s8

036844146c2aa41487fd1551e31c7271.png

现在活动的端口是enp0s8,我们断开这个端口,看一下主备模式配置是否工作:

[root@localhost ~]# nmcli device disconnect enp0s8

Device 'enp0s8' successfully disconnected.

[root@localhost ~]# teamdctl team0 state

setup:

runner: activebackup

ports:

enp0s3

link watches:

link summary: up

instance[link_watch_0]:

name: ethtool

link: up

down count: 0

runner:

active port: enp0s3

看到活动接口切换到enp0s3上面了。

76433b7689932e3e1df7053c57d1b97e.png

总结

主备模式的链路聚合将其中一个接口置于备份状态,并且仅当活动接口断开链接时才会使其处于活动状态。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值