CentOS多网卡绑定

防伪码:没有相当程度的孤独是不可能有内心的平和。

1、概述

随着技术的发展,四张及以上的千兆以太网卡已经变成了服务器的标配。而在生产环境中,为了保证Linux服务器的网络稳定,会对服务器的多张网卡通过绑定一个IP来实现网卡的热备。

网卡绑定的模式(mode)共有七种(0~6) bond0、bond1、bond2、bond3、bond4、bond5、bond6

其中常用的有三种:

mode=0:平衡负载模式,有自动备援,但需要交换机支持。

mode=1:active-backup,主-备份策略,自动备援模式,其中一条线若断线,其他线路将会自动切换过去。而且MAC地址是外部可见得,从外面看来,bond的MAC地址是唯一的,以避免交换机发生混乱。此模式只提供了容错能力,没有负载功能。优点是可以提供高网络连接的可用性,但是它的资源利用率较低,只有一个接口处于工作状态,在有 N 个网络接口的情况下,资源利用率为1/N。

mode=6:平衡负载模式,有自动备援,不需要交换机支持。接收负载均衡是通过ARP协商实现的。bonding驱动截获本机发送的ARP应答,并把源硬件地址改写为bond中某个slave的唯一硬件地址,从而使得不同的对端使用不同的硬件地址进行通信。

2、mode=1测试

2.1 测试环境

主机名 IP 系统
test-01 192.168.10.51 CentOS release 6.9 (Final)

本次测试通过VMware Workstation模拟。

2.2 添加网卡

在【虚拟机设置】中添加网络适配器。

查看网卡是否添加:

[[email protected] ~]#ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0C:29:66:30:36
inet addr:192.168.10.51  Bcast:192.168.10.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe66:3036/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:91 errors:0 dropped:0 overruns:0 frame:0
TX packets:76 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9813 (9.5 KiB)  TX bytes:11278 (11.0 KiB)
eth1      Link encap:Ethernet  HWaddr 00:0C:29:66:30:40
BROADCAST MULTICAST  MTU:1500  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
lo        Link encap:Local Loopback
inet addr:127.0.0.1  Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING  MTU:65536  Metric:1
RX packets:80 errors:0 dropped:0 overruns:0 frame:0
TX packets:80 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5360 (5.2 KiB)  TX bytes:5360 (5.2 KiB)

2.3 创建bond

[[email protected] ~]#cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]#cp ifcfg-eth0 ifcfg-bond0
[[email protected] network-scripts]#vim ifcfg-bond0
DEVICE=bond0
TYPE=Ethernet
ONBOOT=on
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.10.51
GATEWAY=192.168.10.2
NETMASK=255.255.255.0
DNS1=223.5.5.5

修改eth0:

[[email protected] network-scripts]#vim ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=on
BOOTPROTO=none
MASTER=bond0
SLAVE=yes

修改eth1:

[[email protected] network-scripts]#vim ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=on
BOOTPROTO=none
MASTER=bond0
SLAVE=yes

说明:MASTER=bond0和SLAVE=yes这两行主要是用于系统service network restart后自动启用。

2.4 模块加载

[[email protected] network-scripts]#echo "alias bond0 bonding" >>/etc/modprobe.d/dist.conf
[[email protected] network-scripts]#echo "options bond0 mode=1 miimon=100" >>/etc/modprobe.d/dist.conf

说明:miimon是用来进行链路监测的,单位是ms(毫秒),即系统每100ms监测一次链路连接状态,若有一条线路不通就转入另一条线路。

2.5 重启网卡

[[email protected] ~]#service network restart

bond0、eth0和eth1的MAC地址均变成之前eth0的MAC地址。

[[email protected] network-scripts]#ifconfig
bond0     Link encap:Ethernet  HWaddr 00:0C:29:66:30:36
inet addr:192.168.10.51  Bcast:192.168.10.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe66:3036/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
RX packets:33 errors:0 dropped:0 overruns:0 frame:0
TX packets:31 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2508 (2.4 KiB)  TX bytes:3486 (3.4 KiB)
eth0      Link encap:Ethernet  HWaddr 00:0C:29:66:30:36
UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:971 errors:0 dropped:0 overruns:0 frame:0
TX packets:686 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:91772 (89.6 KiB)  TX bytes:103730 (101.2 KiB)
eth1      Link encap:Ethernet  HWaddr 00:0C:29:66:30:36
UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:14 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:872 (872.0 b)  TX bytes:0 (0.0 b)
lo        Link encap:Local Loopback
inet addr:127.0.0.1  Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING  MTU:65536  Metric:1
RX packets:80 errors:0 dropped:0 overruns:0 frame:0
TX packets:80 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5360 (5.2 KiB)  TX bytes:5360 (5.2 KiB)

3、验证

3.1 断开eth0测试

宿主机ping192.168.10.51测试:

ping 192.168.10.51

断开eth0,观察到bond已经切换到eth1:

[[email protected] ~]#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: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 00:0c:29:66:30:36
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 00:0c:29:66:30:40
Slave queue ID: 0

在宿主机上观察到ping有一次丢包:

正在 Ping 192.168.10.51 具有 32 字节的数据:
来自 192.168.10.51 的回复: 字节=32 时间=1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
请求超时。
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64

3.2 断开eth1测试

同理,连接eth0,断开eth1,bond切换到eth0:

[[email protected] ~]#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): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 00:0c:29:66:30:36
Slave queue ID: 0
Slave Interface: eth1
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 2
Permanent HW addr: 00:0c:29:66:30:40
Slave queue ID: 0

切换的时候也丢了一次包:

来自 192.168.10.51 的回复: 字节=32 时间=1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
请求超时。
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
请求超时。
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.51 的回复: 字节=32 时间<1ms TTL=64
时间: 2024-08-03 04:17:20

CentOS多网卡绑定的相关文章

CentOS双网卡绑定bond0

a)拷?并配置vim /etc/sysconfig/network-scripts/ifcfg-bond0配置?件(会自动创建文件) DEVICE=bond0 TYPE=Ethernet ONBOOT=yes BOOTPROTO=static IPADDR=xxx.xxx.xxx.xxx NETMASK=xxx.xxx.xxx.xxx GATEWAY=xxx.xxx.xxx.xxx USERCTL=no b)编辑em1,em2/eth0.eth1?件 vim /etc/sysconfig/net

CentOS 双网卡绑定实现平衡负载

绑定两块网卡主要为了解决网卡故障.负载均衡等问题. 1.在vm加一块网卡,登录后检查网卡是否识别. 分别用ip addr和nmcli查看网卡的情况 [[email protected]-senior01 ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 1

bond双网卡绑定

centos双网卡绑定 在/etc/sysconfig/network-scripts/目录下建立ifcfg-bond0文件,文件内容如下: DEVICE=bond0 USERCTL=no BOOTPROTO=none ONBOOT=yes IPADDR=192.168.100.17 NETMASK=255.255.255.0 GATEWAY=192.168.100.1 TYPE=UnKnown BONDING_OPTS="miimon=80 mode=0" 绑定mode为0,是ron

Lnux系统网卡绑定配置详解

一.CentOS 配置网卡绑定(bonding) 1.bonding概述 (1)作用:就是将多块网卡绑定同一IP地址对外提供服务,可以实现高可用或者负载均衡.当然,直接给两块网卡设置同一IP地址是不可能的.通过bonding,虚拟一块网卡对外提供连接,物理网卡的被修改为相同的MAC地址. (2)Bonding的工作模式 1)Mode 0 (balance-rr)轮转(Round-robin)策略:从头到尾顺序的在每一个slave接口上面发送数据包.本模式提供负载均衡和容错的能力 2)Mode 1

Linux下多网卡绑定(bond)

     网卡绑定mode共有七种(0~6) bond0.bond1.bond2.bond3.bond4.bond5.bond6 常用的有三种 mode=0:平衡负载模式,有自动备援,但需要"Switch"支援及设定. mode=1:自动备援模式,其中一条线若断线,其他线路将会自动备援. mode=6:平衡负载模式,有自动备援,不必"Switch"支援及设定. 需要说明的是如果想做成mode 0的负载均衡,仅仅设置这里options bond0 miimon=100

Centos 6.5 64位双网卡绑定

1.环境描述      我的Vmware workstation 10 安装Centos 6.5 64位加上双口的Intel千兆网卡,通过ifconfig -a|grep eth命令看到eth2和eth3两张网卡. 2.双网卡绑定步骤: 2.1 修改/etc/sysconfig/network-scripts/ifcfg-eth2配置文档,修改后的内容如下:    DEVICE=eth2       ONBOOT=yes              #系统启动时自动启用该设备    BOOTPRO

CentOS 5.x 6.x 网卡绑定(Bonding)脚本

工作中经常要为客户调整网卡绑定,为此制作了此脚本(比较粗糙,请见谅).使用时请查看脚本帮助 bond.sh #!/bin/bash usage() { cat << EOF create by [email protected] usage: $0 options OPTIONS:     -h  Show this message     -i Bonding IP,NETMASK,GATEWAY(optional)     -q Show Bonding Parameter Info   

centos 6.4系统双网卡绑定配置详解

Linux双网卡绑定实现就是使用两块网卡虚拟成为一块网卡(需要交换机支持),这个聚合起来的设备看起来是一个单独的以太网接口设备,通俗点讲就是两块网卡具有相同的IP地址而并行链接聚合成一个逻辑链路工作.本文详细描述下centos 6.4系统双网卡绑定操作步骤操作前需要确定NetworkManager 服务是否已经停止,否则容易报错.#service NetworkManager status显示NetworkManager 已停即可 具体绑定操作:1.在/etc/sysconfig/network

CentOS 7.6网卡绑定mode1

CentOS 7.6网卡绑定mode1 [[email protected] ~]# systemctl stop NetworkManager[[email protected] ~]# systemctl disable NetworkManager[[email protected] ~]# lsmod |grep bonding[[email protected] ~]# modprobe --first-time bonding[[email protected] ~]# setenf