zoukankan      html  css  js  c++  java
  • Linux双网卡绑定配置

    Linux双网卡绑定配置  

                                       

    环境介绍

    Linux Redhat 6.5、4张网卡

    需求

    4张网卡两两绑定,4张网卡分别是eth0/eth1/eth2/eth3

    其中eth0/eth2绑定(bond0)、eth1/eth3绑定(bond1)

     

    原理介绍

    什么是bind?

    将多块网卡虚拟成为一块网卡的技术,通过bond技术让多块网卡看起来是一个单独的以太网接口设备并具有相同的ip地址。

    双网卡工作原理

    网卡工作在混杂(promisc)模式,接收到达网卡的所有数据包,tcpdump工作用的也是混杂模式(promisc),将两块网卡的 MAC地址修改为相同接收特定MAC的数据帧,然后把相应的数据帧传送给bond驱动程序进行处理。

     

      mode=1:在主备模式下,只有主网卡eth0工作,eth1作为备份网卡是不工作的,只有当一个网络接口失效时(例如交换机掉电等),为了不会出现网络中断,系统会按照配置指定的网卡顺序启动工作,保证机器仍能对外服务,起到了失效保护功能。

      mode=0:在负载均衡模式下,两块网卡都工作,提供两倍带宽。

     

     

    配置步骤

    1、首先查看所有的网口

    [root@rac-node1 ~]# ifconfig -a

     

    2、编辑网口配置文件

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


    [root@rac-node1 network-scripts]# ls

    [root@rac-node1 network-scripts]# vim ifcfg-eth0

    [root@rac-node1 network-scripts]# cat ifcfg-eth0

    DEVICE=eth0

    HWADDR=00:0C:29:84:D2:EB

    TYPE=Ethernet

    UUID=b93ebcc4-90bc-4357-85d8-6ccb417fcc57

    ONBOOT=yes

    NM_CONTROLLED=no

    BOOTPROTO=none

    none表示不使用任何协议

    static表示设置静态IP

    dhcp表示动态获取IP

     

    MASTER=bond0  #指定虚拟网口的名字(主人)

    SLAVE=yes #备用(从设备)

     [root@rac-node1 network-scripts]# vim ifcfg-eth2

    [root@rac-node1 network-scripts]# cat ifcfg-eth2

    DEVICE=eth2

    HWADDR=00:0C:29:84:D2:FF

    TYPE=Ethernet

    UUID=57cce5b3-23c6-47e7-aca5-86c2358f314f

    ONBOOT=yes

    NM_CONTROLLED=no

    BOOTPROTO=none

    none表示不使用任何协议

    static表示设置静态IP

    dhcp表示动态获取IP

    MASTER=bond0  #指定虚拟网口的名字(主人)

    SLAVE=yes#备用(从设备)

     

    [root@rac-node1 network-scripts]# touch ifcfg-bond0

    [root@rac-node1 network-scripts]# vim ifcfg-bond0

    [root@rac-node1 network-scripts]# cat ifcfg-bond0

    DEVICE=bond0

    TYPE=Ethernet

    ONBOOT=yes

    BOOTPROTO=static

    IPADDR=192.168.16.131

    NETMASK=255.255.255.0

    #GATEWAY=192.168.16.1

     

    3、配置bonding

    [root@rac-node1 network-scripts]# vim /etc/modprobe.d/dist.conf

    末尾增加以下两行

    alias bond0 bonding

    options bond0 miimon=100 mode=1

    #miimon是用来进行链路监测的:miimon=100表示系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路。

    #mode=1表示属于主备模式。

     

    4、设置开机自启动

    在/etc/rc.d/rc.local文件中加入如下语句

    [root@rac-node1 network-scripts]# vim /etc/rc.d/rc.local

    ifenslave bond0 eth0 eth2 ---系统启动自动运行

    #route add -net 192.168.xxx.0 netmask 255.255.255.0 bond0---如果有需要添加该路由

     

    5、重启

    不能重启服务(重启网络服务不能使双网卡绑定生效),只能重启主机。

     

    6、查询当前哪个网口是主用网口

    [root@rac-node1 ~]# 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  #主用网口

    MII Status: up

    MII Polling Interval (ms): 100

    Up Delay (ms): 0

    Down Delay (ms): 0

     

    Slave Interface: eth0

    MII Status: up

    Speed: 10000 Mbps

    Duplex: full

    Link Failure Count: 0

    Permanent HW addr: 00:0c:29:84:d2:eb

    Slave queue ID: 0

     

    Slave Interface: eth2

    MII Status: up

    Speed: 10000 Mbps

    Duplex: full

    Link Failure Count: 0

    Permanent HW addr: 00:0c:29:84:d2:ff

    Slave queue ID: 0

    … … … … …

    剩余两个网口配置方法一致

     

     

    7、测试主备能否切换

    [root@rac-node1 ~]# 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

    MII Status: up

    MII Polling Interval (ms): 100

    Up Delay (ms): 0

    Down Delay (ms): 0

     

    Slave Interface: eth0

    MII Status: up

    Speed: 10000 Mbps

    Duplex: full

    Link Failure Count: 0

    Permanent HW addr: 00:0c:29:84:d2:eb

    Slave queue ID: 0

     

    Slave Interface: eth2

    MII Status: up

    Speed: 10000 Mbps

    Duplex: full

    Link Failure Count: 0

    Permanent HW addr: 00:0c:29:84:d2:ff

    Slave queue ID: 0

     

    [root@rac-node1 ~]# ifdown ifcfg-eth0

    [root@rac-node1 ~]# 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: eth2

    MII Status: up

    MII Polling Interval (ms): 100

    Up Delay (ms): 0

    Down Delay (ms): 0

     

    Slave Interface: eth2

    MII Status: up

    Speed: 10000 Mbps

    Duplex: full

    Link Failure Count: 0

    Permanent HW addr: 00:0c:29:84:d2:ff

    Slave queue ID: 0

     

    注意:

      ①UUID是唯一的编号,每个网口唯一

      ②两个配置文件中HWADDR不能一样,可以不要,因为会自动读取

      ③网口切换后 ifconfig bond0查看到的MAC地址还是切换前的MAC地址-->为了防止IP对应MAC地址混乱

  • 相关阅读:
    September 29th 2017 Week 39th Friday
    September 28th 2017 Week 39th Thursday
    September 27th 2017 Week 39th Wednesday
    September 26th 2017 Week 39th Tuesday
    September 25th 2017 Week 39th Monday
    September 24th 2017 Week 39th Sunday
    angular2 学习笔记 ( Form 表单 )
    angular2 学习笔记 ( Component 组件)
    angular2 学习笔记 ( Http 请求)
    angular2 学习笔记 ( Router 路由 )
  • 原文地址:https://www.cnblogs.com/qgmzhn/p/12119226.html
Copyright © 2011-2022 走看看