双网卡绑定实现就是使用两块网卡虚拟成为一块网卡,这个聚合起来的设备看起来是一个单独的以太网接口设备,通俗点讲就是两块网卡具有相同的IP地址而并行链接聚合成一个逻辑链路工作。根据交换机可支持的功能不同,最常见的是设定为主备方式的双网卡绑定。linux有七种网卡绑定模式:0. round robin,1.active-backup,2.load balancing (xor),3.fault-tolerance (broadcast),4.lacp,5.transmit load balancing,6.adaptive load balancing。
一、操作步骤
这里以绑定两个网卡为示例描述。配置文件都在/etc/sysconfig/network-scripts/目录下。
1、编辑新的ifcfg-bond0文件

# vim /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0

ONBOOT=yes
BOOTPROTO=static

IPADDR=192.168.216.252
NETMASK=255.255.255.0

GATEWAY=192.168.216.1
BONDING_OPTS="mode=1 miimon=100"
这是最后bond0设备的实际IP设置。
2、分别编辑ifcfg-eth0和ifcfg-eth1文件

# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes

BOOTPROTO=none
MASTER=bond0
SLAVE=yes
# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes

BOOTPROTO=none
MASTER=bond0
SLAVE=yes
3、修改/etc/modprobe.d/dist.conf文件

# vi /etc/modprobe.d/dist.conf
添加如下内容:

alias bond0 bonding
options bond0 miimon=100 mode=1

注:由于ifcfg-bond0中已经写了这条,这条在这里可添加也可以不添加)
说明:

miimon是用来进行链路监测的。 比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;
mode的值表示工作模式,他共有0,1,2,3四种模式,常用的为0,1两种。需根据交换机可提供的工作模式选择。
mode=0表示load balancing (round-robin)为负载均衡方式,两块网卡都工作。
mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份。
※ 注意:

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

4、手工导入bonding驱动

#modprobe –i bonding

5、重启网络服务

#service network restart

6、验证一下,发现IP已经运行在bond0设备上了

#ifconfig


二、卸载bond0设备
如需删除双网卡绑定系统,可执行以下操作:

#rm -f /etc/sysconfig/network-scripts/ifcfg-bond0
#vi /etc/etc/modprobe.d/dist.conf
删除以下两行后,保存退出

alias bond0 bonding
options bond0 miimon=100 mode=1
最后重新配置eth0和eth1的IP,并重启网络即可。
三、自动化脚本
从上面的步骤可见,都是固定化的工作,有网友整理了一个脚本出来,运行 # ./newbond.sh即可,脚本如下:

#!/bin/bash

if [ $# -lt 6 ];then

    echo "Usage: $0 <bond*> <eth*> <eth*> <ipaddress> <netmask> <gateway>"

    echo "eg: $0 bond0 eth0 eth1 10.0.0.1 255.255.255.0 10.0.0.254"

    exit 1

fi

 

#modify ifcfg-bond* file

echo "DEVICE=$1

IPADDR=$4

NETMASK=$5

GATEWAY=$6

ONBOOT=yes

BOOTPROTO=none

USERCTL=no" >/tmp/ifcfg-$1

mv -f /tmp/ifcfg-$1 /etc/sysconfig/network-scripts/

 

#modify ifcfg-eth0 file

echo "DEVICE=$2

USERCTL=no

ONBOOT=yes

MASTER=$1

SLAVE=yes

BOOTPROTO=none" >/tmp/ifcfg-$2

mv -f /tmp/ifcfg-$2 /etc/sysconfig/network-scripts/

 

#modify ifcfg-eth1 file

echo "DEVICE=$3

USERCTL=no

ONBOOT=yes

MASTER=$1

SLAVE=yes

BOOTPROTO=none" >/tmp/ifcfg-$3

mv -f /tmp/ifcfg-$3 /etc/sysconfig/network-scripts/

 

#modify network file

#sed /GATEWAY/d /etc/sysconfig/network >/tmp/network

#echo "GATEWAY=\"$6\"">>/tmp/network

#mv -f /tmp/network /etc/sysconfig/

 

#modify modules.cof/modprobe.cof

MODCONF=/NULL

TEMPFILE1=/tmp/mod1.$$

TEMPFILE2=/tmp/mod2.$$

BAKFILE=/etc/.modconf

 

echo "Please Select Your Bond Mode:(balance-rr/active-backup)or(0/1)?"

read MODE

 

if [ -f /etc/modprobe.conf ]; then

    MODCONF=/etc/modprobe.conf

else

    MODCONF=/etc/modules.conf

fi

 

cp $MODCONF $BAKFILE

 

sed '/alias[ \t]*'$1'[ \t]*bonding/d;/options[ \t]*'$1'[ \t]*/d;/install.*'$1'/d' $MODCONF > $TEMPFILE1

cp $TEMPFILE1 $TEMPFILE2

 

if [ "$(grep "alias.*bonding" $TEMPFILE1)" != "" ]; then

    bondcount=$(grep "alias.*bonding" $TEMPFILE1 | wc -l)

elif [ "$(grep "install.*bond.*" $TEMPFILE1)" != "" ]; then

    bondcount=$(grep "install.*bond.*" $TEMPFILE1 | wc -l)

else

    bondcount=0

fi

 

if [ "$bondcount" -ge 1 ]; then

    sed '/alias.*bonding/d;s/\(options[ \t]*\)\(bond[0-9]*\)/install\ \2\ \/sbin\/modprobe\ --ignore-install\ bonding\ -o\ \2/' $TEMPFILE1 > $TEMPFILE2

 

    echo "install $1 /sbin/modprobe --ignore-install bonding -o $1 miimon=100 mode=$MODE" >> $TEMPFILE2

else

 

    echo "alias $1 bonding" >> $TEMPFILE2

    echo "options $1 miimon=100 mode=$MODE" >> $TEMPFILE2

fi    

    mv -f $TEMPFILE2 $MODCONF

 

#restart network

echo "System will restart network continue(y/n)?"

read bb

if [ "$bb" = "y" ] || [ "$bb" = "yes" ] || [ "$bb" = "Y" ];then

    for tempmod in $(lsmod | grep -i bond | awk '{print $1}')

    do

    modprobe -r bonding -o "$tempmod"

    done

 

    /etc/init.d/network restart

fi

echo "OK!"

exit 0

Linux双网卡绑定和解除绑定的实现的更多相关文章

  1. Linux 双网卡绑定

    Linux 双网卡绑定 Linux 双网卡绑定双网卡绑定的常用模式:mode1:active-backup 模式,即主备模式.mode0:round-broin 模式,即负载均衡模式(需要交换机配置聚 ...

  2. Linux 双网卡绑定技术

    bond技术是在linux2.4以后加入内核. 一般步骤是1.把bonding模块加入内核, 2 编辑要绑定的网卡设置,去除地址设定 3 添加bond设备,设置地址等配置 4  重启网络 5 在交换机 ...

  3. Linux双网卡绑定

    Linux双网卡绑定 作者:Eric 微信:loveoracle11g eth0和eth1绑定为bond0 [root@rac-node1 ~]# cat /etc/sysconfig/network ...

  4. Linux双网卡绑定bond详解--单网卡绑定多个IP

    Linux双网卡绑定bond详解 1 什么是bond 网卡bond是通过多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在生产场景中是一种常用的技术.Kernels 2.4.12及 ...

  5. Linux双网卡绑定配置

    Linux双网卡绑定配置                                       环境介绍 Linux Redhat 6.5.4张网卡 需求 4张网卡两两绑定,4张网卡分别是eth ...

  6. Linux 双网卡绑定及Bridge

    Linux 双网卡绑定及Bridge 阅读(5,202) 一:linux操作系统下双网卡绑定有七种模式.现在一般的企业都会使用双网卡接入,这样既能添加网络带宽,同时又能做相应的冗余,可以说是好处多多. ...

  7. Linux双网卡绑定和解除

    转载双网卡绑定和解除  一定要在服务管理中关闭NetworkManager服务并禁用自动启动,因为NetworkManager服务是实时生效的,一旦设置错,管理员就得回到机房接显示器配置网络连接. 以 ...

  8. 天道神诀--linux双网卡绑定

    # linux6 双网卡绑定操作步骤 1.彻底关闭NetworkManager service NetworkManager stopchkconfig NetworkManager off 2.编辑 ...

  9. 详解Linux双网卡绑定之bond0

    1.什么是bond? 网卡bond是通过多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在生产场景中是一种常用的技术.Kernels 2.4.12及以后的版本均供bonding模块 ...

随机推荐

  1. 基数排序详解以及java实现

    前言 基数排序(radix sort)又称桶排序(bucket sort),相对于常见的比较排序,基数排序是一种分配式排序,即通过将所有数字分配到应在的位置最后再覆盖到原数组完成排序的过程.我在上一篇 ...

  2. vtk点云数据的显示[转]

    #include "vtkActor.h" #include "vtkRenderer.h" #include "vtkRenderWindow.h& ...

  3. VC++ 中滑动条(slider控件)使用 [转+补充]

    滑动控件slider是Windows中最常用的控件之一.一般而言它是由一个滑动条,一个滑块和可选的刻度组成,用户可以通过移动滑块在相应的控件中显示对应的值.通常,在滑动控件附近一定有标签控件或编辑框控 ...

  4. Form动态下拉框

    FORM级触发器:WHEN-NEW-FORM-INSTANCE   1.定义:      V_LIST_NAME11 VARCHAR2(100) := 'QUERY_FIND.UPDATE_TYPE' ...

  5. Programming pages of Jasper Neumann

    http://programming.sirrida.de/ Discussion topics Bit permutations Download source files List of func ...

  6. USB DATA Toggle

    For bulk and interrupt transfers, the data toggle resets <0> only on Set Configuration, Set In ...

  7. uva539 The Settlers of Catan

    The Settlers of Catan Within Settlers of Catan, the 1995 German game of the year, players attempt to ...

  8. php实现工厂模式

    设计模式-使用php实现工厂方法模式 [概要] 创建型模式 定义一个用于创建对象的接口,让子类决定实例化哪一个类.Factory Method使用一个类的实例化延迟到其子类[GOF95] [结构图] ...

  9. iOS开发——实战OC篇&环境搭建之StoryBoard(玩转UINavigationController与UITabBarController)

      环境搭建之StoryBoard(玩转UINavigationController与UITabBarController)   研究了这么就IOS开发,都没有所处一个像样或者自己忙一点的项目.最近自 ...

  10. MySQL--索引条件下推优化

    http://blog.163.com/li_hx/blog/static/1839914132015782821512/ 一 什么是“索引条件下推” “索引条件下推”,称为 Index Condit ...