linux bond四网卡绑定,Linux服务器网卡绑定bond配置

原文

网卡绑定是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡。bond在实际网络应用部署中是一种常用的技术

下面介绍如何在CentOS服务器上实现网卡绑定

b9204924dac023dc8470edb2eceb96c2.png

1、服务器ifconfig查看可以看到有两块网卡eth0,eth1

fbc6b27ee6f314a92ba37d6346616c25.png

要实现物理网口eth0,eth1网卡绑定,绑定后的虚拟逻辑网口bond0 IP地址和原来的eth0的IP保持一致

2、modinfo bonding 检查自己的操作系统是否支持bonding

e424591dfbbbae8e2c729cc0bcb6b137.png

如果没有消息返回,说明内核不支持bonding,需要重新编译内核

3、检查ifenslave,是否有这个命令

aadcd4bf15a956a0adc1f2fcca005bd4.png

4、接下来进入正题

在cd /etc/sysconfig/network-scripts/下创建ifcfg-bond0配置文件

[[email protected] ~]# cd /etc/sysconfig/network-scripts/

[[email protected] network-scripts]# vi ifcfg-bond0

DEVICE=bond0

TYPE=Ethernet

ONBOOT=yes

BOOTPROTO=none

IPADDR=192.168.31.2

NETMASK=255.255.255.0

GATEWAY=192.168.31.1

DNS1=114.114.114.114

DNS2=1.1.1.1

USERCTL=no

0e14087c898db219b8ce7508a62898c6.png

接下来修改ifcfg-eth0和ifcfg-eth1两块物理网卡的配置文件

将原有的IP、子网掩码、网关信息等信息全部删除,修改成如下格式

[[email protected] ~]# cd /etc/sysconfig/network-scripts/

[[email protected] network-scripts]# vi ifcfg-eth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

efe99ef70d55cd74b9e81022e8a99a8e.png

[[email protected] network-scripts]# vi ifcfg-eth1

DEVICE=eth1

ONBOOT=yes

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

51551813cb80a7f6a31ff13f9d251418.png

5、修改modprobe相关设定文件,并加载bonding模块

vi /etc/modprobe.d/bonding.conf

alias bond0 bonding

options bonding mode=6 miimon=200

e1c0a2ad2daf8b4fa7e9aa7198830e32.png

加载bonding模块

[[email protected] ~]# modprobe bonding

如果这时是SecureCRT等SSH终端连接的服务器后台,会话可能会断开,在服务器上确认bonding模块是否加载,然后用service network restart或者/etc/init.d/network restart命令重启网络

[[email protected] ~]# lsmod | grep bonding

bonding               132885  0

[[email protected] ~]# service network restart

Shutting down interface bond0:  [  OK  ]

Shutting down loopback interface:  [  OK  ]

Bringing up loopback interface:  [  OK  ]

Bringing up interface bond0:  Determining if ip address 192.168.31.2 is already in use for device bond0...

[  OK  ]

66038fe1634e6ebffe679c8ac577e3d1.png

查看bond网卡绑定后的模式

cat /proc/net/bonding/bond0

[[email protected] ~]# cat /proc/net/bonding/bond0

91214e7d70476de9e37cc10698179411.png

6、测试一下负载均衡功能

手动断开eth0链路的网线,看网络是否还通

如下图所示ethtool eth0 可以看到eth0网口已经断开,右侧可以看到ping 192.168.31.1网关一直可以ping通

bcbbaaafc98d0e176ceedd0d81fc7e6d.png

注:mode bond网卡绑定的几种模式之前有介绍,请参见本公众号历史文章

mode:Mode of operation

0 for balance-rr,

1 for active-backup,

2 for balance-xor,

3 for broadcast,

4 for 802.3ad,

5 for balance-tlb,

6 for balance-alb (charp)

原文:https://www.cnblogs.com/itfat/p/12342028.html