首页 > 技术知识 > 正文

一、Linux下网口绑定的设置方法

1、在/etc/sysconfig/network-scripts/目录下创建一个设备名为”bond0″的接口配置文件,配置IP地址等信息

# vim /etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 IPADDR=192.168.241.57 NETMASK=255.255.255.0 ONBOOT=yes NAME=bond0 BOOTPROTO=none

2、配置设备名为”bond0″的子端口配置文件,”MASTER=bond0″:标识eth1的上层接口为bond0;”SLAVE=yes”:标识为eth1为子接口

# vi ifcfg-eth1 DEVICE=”eth1″ ONBOOT=”yes” BOOTPROTO=none MASTER=bond0 SLAVE=yes

这里有一个小Tip,如果有很多端口,不知道要绑定哪些,可以用ethtool eth1这样的命令来查看各个端口的详细情况,比如速率,是千兆还是万兆等等

3、在/etc/modprobe.d、目录下创建名为modules.conf 文件,加入如下内容,其中 miimon=100为链路检测时间,mode=6表示为:bond模式为6(balance-alb)

#vim /etc/modprobe.d/bonding.conf alias bond0 bonding options bonding mode=6 miimon=100

4、重新加载绑定模块

#modprobe bonding

5、重新启动网络服务

#/etc/init.d/network restart

p.s.解除绑定的做法就是相反将相应的配置文件去掉,卸载绑定模块,设置原先slave网口的IP,重启网络:

<span style=”font-size:14px;”>[root@client04 ~]# rm -f /etc/sysconfig/network-scripts/ifcfg-bond0 [root@client04 ~]# rm -f /etc/modprobe.d/modules.conf [root@client04 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 [root@client04 ~]# modprobe -r bonding [root@client04 ~]# service network restart</span>

如果重启网络有问题,可以/etc/udev/rules.d/70-persistent-net.rules 删除后重启机器,这个文件绑定了网卡和mac地址,直接删除重启,会自动生成

二、交换机设置

有一些绑定模式是不需要交换机支持的,比如上面mode6的例子,有些是需要的,比如Mode0,4…

Mode0绑定,交换机设置:

步骤是这样的

进串口:

sudo minicom

1、登录到交换机

show interface ethernet status

查看端口状态

如下图所示这个交换机是个IB交换机,一分四每个分一个万兆,中间的1,2.。。是真实的交换机上的网卡,后面的每一个有4个,是接到服务器上的网口,服务器是万兆的,所以一分四后每一个对应一个服务器上的万兆网口,可以看到每一个的速率都是10Gb,后面的状态就是网口UP还是DWON。

网口绑定的方法

2、登录到你的客户端

Ifdown bond0 ifdown eth0 看哪个接口down了 记住这个端口号 然后在交换机上show interface ethernet status 然后ifup eth0 ifdown你的那一个bond子接口 再从交换机上show interface ethernet status 看哪个接口down了,记住这个端口号 进入配置模式: configure t 然后在交换机上输入interface port-channel 5 你们从5开始编号,下个机器号为6,下面依次加1 退出配置模式:exit 然后输入:interface ethernet 1/1/4(你之前记住的号) channel-group 5(你编的号) mode on

以上步骤每个子端口都操作一遍

3、在你的客户端上vi /etc/modpobre.d/bonding.conf 文件

修改mode=0

然后modprobe -r bonding

modprobe bonding

ifup bond0

cat /proc/net/bonding/bond0检查一下

4、交换机配置完成后write memory 保存一下配置

write memory

三、/proc/net/bonding/bond0下的文件可以查看绑定状态,如下图所示:

网口绑定的方法1

转载:https://blog.csdn.net/uj_mosquito/article/details/41120619

猜你喜欢