linux系统bonding

转自:http://yanghuawu.blog.51cto.com/2638960/1160819

================================================

  

双网卡绑定单个IP 地址 为了提供网络的高可用性,我们可能需要将多块网卡绑定成一块虚拟网卡对外提供服务,这样即使其中的一块物理网卡出现故障,也不会导致连接中断。多网卡绑。

 

为了提供网络的高可用性,我们可能需要将多块网卡绑定成一块虚拟网卡对外提供服务,这样即使其中的一块物理网卡出现故障,也不会导致连接中断。在Linux下叫bonding,IBM称为etherchanel,broadcom叫team,但是名字怎么变,效果都是将两块或更多的网卡当做一块网卡使用,在增加带宽的同时也可以提高冗余性。比如我们在CentOS 6.3下可以将eth0和eth1绑定成虚拟网卡bond0。

如图:

 

 

实验配置:

mode=1:表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,其中一块网卡在工作(若eth0断掉),则自动切换到另一个块网卡(eth1做备份)。

 

系 统

设备名称

IP地址

子网掩码

 

CentOS 6.3_64bit

eth0

 

 

eth1

 

 

bond0

10.1.3.210

255.255.255.0

 

1、查看主机网卡

[root@web ~]# cd /etc/sysconfig/network-scripts/

[root@web1 network-scripts]# ll

total 200

-rw-r--r--. 1 root root   212 Mar 20 22:15 ifcfg-eth0

-rw-r--r--  1 root root   212 Mar 23 19:10 ifcfg-eth1

 

2、复制ifcfg-bond0

[root@web network-scripts]# cp ifcfg-eth0 ifcfg-bond0

[root@web network-scripts]# ll

total 204

-rw-r--r--  1 root root   212 Mar 23 19:12 ifcfg-bond0

-rw-r--r--. 1 root root   212 Mar 20 22:15 ifcfg-eth0

-rw-r--r--  1 root root   212 Mar 23 19:10 ifcfg-eth1

 

3、编辑ifcfg-bond0、ifcfg-eth0、ifcfg-eth1

[root@web network-scripts]# vim ifcfg-bond0

DEVICE=bond0

BOOTPROTO=static

IPADDR=10.1.3.210

NETMASK=255.255.255.0

GATEWAY=10.1.3.254

ONBOOT=yes

USERCTL=no

 

[root@web1 network-scripts]# vim ifcfg-eth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

 

[root@web1 network-scripts]# vim ifcfg-eth1

DEVICE=eth1

ONBOOT=yes

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

 

4、模块加载

[root@web1 ~]# vim /etc/modprobe.d/dist.conf 

在最后添加以下内容:

#加载bonding模块,对外虚拟网络接口设备为 bond0

alias bond0 bonding

options bond0 miimon=100 mode=1

 

[root@web1 ~]# grep bond0 /etc/modprobe.d/dist.conf

alias bond0 bonding

options bond0 miimon=100 mode=1

 

说明:

miimon是用来进行链路监测的。 比如:miimon=100,单位是ms(毫秒)这边的100,是100ms,即是0.1秒那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;mode的值表示工作模式,他共有0,1,2,3四种模式,常用的为0、1两种。 

mode共有七种(0~6),这里解释两个常用的选项。

mode=0:表示load balancing (round-robin)为负载均衡方式,两块网卡都在工作。

mode=1:表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,其中一块网卡在工作(若eth0断掉),则自动切换到另一个块网卡(eth1做备份)。

bonding只能提供链路监测,即从主机到交换机的链路是否接通。如果只是交换机对外的链路down掉了,而交换机本身并没有故障,那么bonding会认为链路没有问题而继续使用。

 

 

5、重启网络服务,使配置生效

[root@web1 ~]# service network restart

Shutting down interface eth0:                              [  OK  ]

Shutting down interface eth1:                              [  OK  ]

Shutting down loopback interface:                           [  OK  ]

Bringing up loopback interface:                             [  OK  ]

Bringing up interface bond0:  RTNETLINK answers: File exists

Error adding address 10.1.3.210 for bond0.

RTNETLINK answers: File exists                              [  OK  ]

6、查看bond0接口状态

[root@web1 ~]# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

 

Bonding Mode: fault-tolerance (active-backup)

Primary Slave: None

Currently Active Slave: eth0       // 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: 0

Permanent HW addr: 00:0c:29:c9:6d:18

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:c9:6d:22

Slave queue ID: 0

 

7、查看中路由表状态:

[root@web1 ~]#  route  -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.1.3.0        0.0.0.0         255.255.255.0   U     0      0        0 bond0

169.254.0.0     0.0.0.0         255.255.0.0     U     1004   0        0 bond0

0.0.0.0         10.1.3.254      0.0.0.0         UG    0      0        0 bond0

[root@web1 ~]# lsmod | grep bond

bonding               127060  0

 

8、测试

选择一台windows 7机器ping测试机,然后停掉当前使用的网卡eth0,查看是否能够继续ping通;

测试结果:

丢失一个包。

 

 

 

查看bond0接口状态

[root@web1 ~]# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

 

Bonding Mode: fault-tolerance (active-backup)

Primary Slave: None

Currently Active Slave: eth1      //eth1为主模式

MII Status: up

MII Polling Interval (ms): 100

Up Delay (ms): 0

Down Delay (ms): 0

 

Slave Interface: eth0

MII Status: down

Speed: Unknown

Duplex: Unknown

Link Failure Count: 1

Permanent HW addr: 00:0c:29:c9:6d:18

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:c9:6d:22

Slave queue ID: 0

 

配置完成!

转载于:https://www.cnblogs.com/water-sky/p/5946168.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux中,接口是网络设备的一个实例,可以是物理网卡或者虚拟设备。Bridge是用来连接多个网络设备的设备,可以实现数据包的转发。VLAN是虚拟局域网,在一个物理网络中创建多个逻辑网络。Bonding是将多个物理网卡绑定在一起,增加网络带宽和冗余。 对于接口的配置,首先需要通过ifcfg-ethX文件配置物理网卡ethX的基本信息,如IP地址、子网掩码等。通过ifcfg-bondX文件配置Bond设备的基本信息,包括类型、绑定的物理网卡、IP地址等。对于Bond的子接口,需要在ifcfg-bondX文件中配置VLAN信息,并将其划入桥接设备中。 在配置VLAN时,需要在ifcfg-bondX文件中指定VLAN=yes,并在ifcfg-bridgeX文件中配置桥的相关信息,如类型、绑定的物理网卡、IP地址等。 如果要配置虚拟机的网络连接,可以将虚拟机连接到相应的桥上,实现二层隔离。对于物理机的子接口,如果需要配置IP,应该配置在桥上。 总结起来,Linux中的接口配置涉及到物理网卡、Bridge、VLAN和Bonding,通过配置相应的配置文件,可以实现不同的网络连接和功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [linux kvm bond + vlan + bridge](https://blog.csdn.net/q965844841qq/article/details/109816043)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [CentOS系统Bonding+VLAN+Bridge配置](https://blog.csdn.net/weixin_28717611/article/details/116947937)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值