Linux下实现网卡绑定(负载均衡和冗余备份)

1 创建网卡配置文件,通过绑定获得的逻辑(虚拟)网卡的名称为bondx,其中x取值0,1,1,...,对于第一组绑定,逻辑网卡的名称为bond0,对应的配置文件为/etc/sysconfig/network-scripts/ifcfg-bond0
#cd /etc/sysconfig/network-scripts
#cp ifcfg-eth0 ifcfg-bond0
2 修改逻辑网卡的配置文件ifcfg-bond0
#vi ifcfg-bond0
device=bond0
bootproto=static
onboot=yes
broadcast=[i]ipaddress[/i]
ipadds=
netmask=
network=
gateway=
userctl=no
type=Ethernet
网卡绑定后,只能在逻辑网卡上配置IP地址,参与绑定的物理网卡不要配置IP地址信息,并删除网卡MAC地址
3 配置ifcfg-eth0和ifcfg-eth1
#vi ifcfg-eth0
device=eth0
bootproto=none
onboot=yes
type=Ethernet
#vi ifcfg-eth1
device=eth1
bootproto=dhcp
onboot=yes
type=Ethernet
4 加载bonding模块
编辑修改/etc/modprobe.conf文件,加入以下内容,使Linux启动时加载bonding模块,支持bond0设备名
alias bond0 bonding
option bond0 miimon=100 mode=0
miimon用于指定每隔多少毫秒(ms)监测一次主机到交换机的链路的连接状态。mode设置绑定的工作模式,其取值为0~6,最常用的主要是0和1模式。0代表负载均衡(balance-rr)模式,1代表冗余备份(active-backup)模式。
插曲:modinfo bonding命令可查询内核是否支持bonding模块
5 配置网卡绑定
#ifenslave bond0 eth0 eth1
通常将该命令添加到/etc/rc.local配置文件
#echo 'ifenslave bond0 eth0 eth1'>>/etc/rc.local
注意:bond0、eth0和eth1网卡的MAC地址都会被系统设置为第一个Slave网卡的MAC地址,即eth0网卡的MAC地址。
大功告成!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值