Linux双网卡链路聚合配置

1、网卡链路聚合配置

网卡配置参数解读:

MASTER=bond0 指定虚拟网口的名字(主人)

SLAVE=yes  备用(从设备)

con-name 指定连接名字,没有特殊要求,

ipv4.methmod 指定获取IP地址的方式

ifname 指定网卡设备名,既就是次配置所生效的网卡

autoconnect 指定是否自动启动

ipv4.addresses 指定IPv4地址

gw4指定网关

前提:

a.检查linux环境是否支持bonding

modinfo bonding

b.加载bonding模块(重启系统后就不用手动加载了)

modprobe bonding

c.确认模块是否加载成功

lsmod | grep bonding

image-20230812162027586

链路聚合配置:

1.查询网卡连接状态,两种状态,连接或者未连接

nmcli device status

image-20230812162340826

image-20230812162357499

2.查询网口带宽

ethtool ens33 | grep -i speed

image-20230812162427762

\3. 创建一块虚拟网卡bond0,并配置模式

设置bond模式mode=1,设置链路检测时间miimon=100ms.

a.不设置链路检测时间,执行如下命令,默认为0ms

nmcli connection add con-name bond0 ifname bond0 type bond mode 1

image-20230812162509291

b.如果要设置链路检测时间,执行如下命令

nmcli connection add con-name bond0 ifname bond0 type bond mode 1 miimon 100

image-20230812162541155

\4. 将接口ens38、ens39加到bond0里去

网卡配置文件目录:cd /etc/sysconfig/network-scripts

image-20230812162603034

a:网卡已有配置文件,执行下面命令, 将接口ens33、ens37加到bond0里去

nmcli connection add type bond-slave ifname ens38 master bond0

nmcli connection add type bond-slave ifname ens39 master bond0

image-20230812162635386

b:网卡无配置文件,执行下面命令, 为ens224和ens256两块网卡创建配置文件并将两块网卡作为bond0网卡的slave

nmcli connection add con-name bond0-port1 ifname ens224 type bond-slave master bond0

nmcli connection add con-name bond0-port2 ifname ens256 type bond-slave master bond0

image-20230812162705571

5.配置bond0口静态ip地址、网关

nmcli connection modify bond0 ipv4.addresses 192.168.3.201/24 ipv4.gateway 192.168.3.1

image-20230812162737258

6.将IP地址获取方式改为手动(manual)获取

nmcli connection modify bond0 ipv4.method manual

image-20230812162806242

7.重载并激活bond0网卡

nmcli connection reload bond0

nmcli connection up bond0

8.验证是否成功

a.查看bond0网卡的带宽

ethtool bond0 | grep -i speed

image-20230812162855619

b.查看bond0网卡的ip地址和两块物理网卡的状态

ip add

image-20230812162924868

c.nmcli connection show

image-20230812162950651

d.查看bond0的详细信息

cat /proc/net/bonding/bond0

image-20230812163018605

2、删除网卡链路聚合

1.直接删除bond0网卡配置文件,以及产生的虚拟网卡配置文件。也可nmtui图形化直接删除。

rm -f ifcfg-bond0

rm -f ifcfg-bond-slave-ens38

rm -f ifcfg-bond-slave-ens39

image-20230812163052771

2.之后重启网络服务。

修改链路检测时间

直接nmtui图形化修改或者配置bond0网卡时添加参数。

posted @ 2023-08-12 17:23  寻梦99  阅读(2981)  评论(0)    收藏  举报