Linux 双网卡绑定

关于网卡绑定模式简介

mode值表示工作模式,共有0\1\2\3\4\5\6\7这7种模式,常用的为0\1\6三种。

mode=0表示load balancing (round-robin)为负载均衡方式,两块网卡都工作。
mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份.
mode=2表示balance-x,提供负载均衡和冗余功能。
mode=3表示broadcast,这个模式提供容错性。
mode=4表示802.3ad,提供了ethtool的迅速,以及使用了802.3ad模式
mode=5表示balance-tlb,自动适应负载均衡,自动切换故障。在此基础上Ethtool支持驱动。
mode=6表示在5模式的基础上优化了arp的广播信息。

常用的网卡绑定驱动模式有:

mode0平衡负载模式(高可用):平时两块网卡均工作,且自动备援,采用交换机设备支援。 #==》不推荐使用
mode1自动备援模式(热备):平时只有一块网卡工作,故障后自动替换为另外的网卡。   #==》推荐使用
mode6平衡负载模式(高可用):平时两块网卡均工作,且自动备援,无须交换机设备支援   #==》推荐使用

环境配置说明:
VMware Workstation 安装CentOS 7操作系统,并添加两块虚拟网卡

image.png

Linux System Environment
[root@test001 ~]# cat /etc/redhat-release                       #==》系统版本
CentOS Linux release 7.5.1804 (Core)
[root@test001 ~]# uname –r                                  #==》系统内核
3.10.0-862.el7.x86_64
[root@test001 ~]# uname -m                                #==》系统位数
x86_64
[root@test001 ~]# echo $LANG                              #==》系统字符集
en_US.UTF-8

网卡绑定模式 mode=1操作步骤

一、创建虚拟聚合网卡接口

[root@test001 ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-bond0
[root@test001 ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0             #==》设备名称
BOOTPROTO=none                #==》手动配置IP地址,也可以设置static
IPADDR=192.168.201.109           #==》IP地址
NETMASK=255.255.255.0           #==》子网掩码
NETWORK=192.168.201.254         #==》网关
BROADCAST=192.168.201.255       #==》广播地址
DNS=192.168.201.10               #==》DNS
ONBOOT=yes                     #==》网卡自启动
USERCTL=no                     #==》是否允许普通用户管理此接口
BONDING_OPTS="miimon=100 mode=1"  #==》配置双网卡模式为1(热备功能),miimon=100网卡切换时间在100毫秒

二、修改第一张网卡eth0配置信息
注意:一定要按照以下配置修改,不用保留UUID等配置

[root@test001 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0       #==》master设备名指定虚拟聚合网卡接口名称
SLAVE=yes           #==》开启SLAVE功能
USERCTL=no         #==》是否允许普通用户管理此接口

三、修改第二张网卡eth1配置信息
注意:一定要按照以下配置修改,不用保留UUID等配置

[root@test001 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0    #==》master设备名指定虚拟聚合网卡接口名称
SLAVE=yes         #==》开启SLAVE功能
USERCTL=no       #==》是否允许普通用户管理此接口

四、重启网卡
注意:如果重启网卡不生效,请重启系统

[root@test001 ~]# systemctl restart network

五、查看状态
注意:如果测试可以使用ping命令进行测试

[root@test001 ~]# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 10
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:87:b5:f0
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:87:b5:fa
Slave queue ID: 0

[root@test001 ~]# ethtool bond0
Settings for bond0:
        Supported ports: [ ]
        Supported link modes:   Not reported
        Supported pause frame use: No
        Supports auto-negotiation: No
        Supported FEC modes: Not reported
        Advertised link modes:  Not reported
        Advertised pause frame use: No
        Advertised auto-negotiation: No
        Advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Port: Other
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: off
        Link detected: yes

网卡绑定模式 mode=6操作步骤与上面操作步骤一样,唯一区别在于bond0网卡配置信息把mode修改成 mod=6即可

一、创建虚拟聚合网卡接口

[root@test001 ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-bond0
[root@test001 ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0             #==》设备名称
BOOTPROTO=none                #==》手动配置IP地址,也可以设置static
IPADDR=192.168.201.109           #==》IP地址
NETMASK=255.255.255.0           #==》子网掩码
NETWORK=192.168.201.254         #==》网关
BROADCAST=192.168.201.255       #==》广播地址
DNS=192.168.201.10               #==》DNS
ONBOOT=yes                     #==》网卡自启动
USERCTL=no                     #==》是否允许普通用户管理此接口
BONDING_OPTS="miimon=100 mode=6"  #==》配置双网卡模式为1(热备功能),miimon=100网卡故障切换时间在100毫秒

二、重启网卡
注意:如果重启网卡不生效,请重启系统

[root@test001 ~]# systemctl restart network

三、查看状态
注意:如果测试可以使用ping命令进行测试

[root@test001 ~]# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: adaptive load balancing
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 10
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:87:b5:f0
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:87:b5:fa
Slave queue ID: 0

[root@test001 ~]# ethtool bond0
Settings for bond0:
        Supported ports: [ ]
        Supported link modes:   Not reported
        Supported pause frame use: No
        Supports auto-negotiation: No
        Supported FEC modes: Not reported
        Advertised link modes:  Not reported
        Advertised pause frame use: No
        Advertised auto-negotiation: No
        Advertised FEC modes: Not reported
        Speed: 2000Mb/s
        Duplex: Full
        Port: Other
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: off
        Link detected: yes
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容