linux双网卡配置

环境:CentOS5.3 Linux version 2.6.18-128.el5,双网卡
配置:
1.编辑/etc/modprobe.conf 文件 
       #vi /etc/modprobe.conf加入如下内容       
       alias bond0 bonding
       options bond0 miimon=100 mode=0
2.新建 bond0 文件 
       #cd /etc/sysconfig/network-scripts 
       #cp ifcfg-eth0 ifcfg-eth0_backup ---(备份要修改的文件) 
       #cp ifcfg-eth0 ifcfg-bond0 
       #vi ifcfg-bond0 
       DEVICE=bond0  ---(将eth0改为bond0)
       IPADDR=192.168.0.231 
       GATEWAY=192.168.0.1
       NETMASK=255.255.255.0 
       ONBOOT=yes 
       BOOTPROTO=none 
       USERCTL=no 
      
3.修改 eth0 文件,只保留必须的选项 
       #vi ifcfg-eth0 
       DEVICE=eth0 
       BOOTPROTO=none 
       ONBOOT=yes 
       MASTER=bond0 
       SLAVE=yes 
       USERCTL=no 
  修改 eth1 的文件,同 eth0,只保留必须的选项 
       DEVICE=eth1 
       BOOTPROTO=none 
       ONBOOT=yes 
       MASTER=bond0 
       SLAVE=yes 
       USERCTL=no 
4.修改/etc/rc.local这个文件,在内容最后添加如下一行:
       #ifenslave bond0 eth0 eth1
5.测试结果,重启服务,建议重新启动计算机 
       #service network restart 
       #ifconfig 显示结果如下
    bond0     Link encap:Ethernet  HWaddr 00:25:64:3D:22:4F 
          inet addr:192.168.0.231  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::225:64ff:fe3d:224f/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:405156 errors:0 dropped:0 overruns:0 frame:0
          TX packets:203264 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:573597691 (547.0 MiB)  TX bytes:13183080 (12.5 MiB)

    eth0      Link encap:Ethernet  HWaddr 00:25:64:3D:22:4F 
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:340351 errors:0 dropped:0 overruns:0 frame:0
          TX packets:171003 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:482384232 (460.0 MiB)  TX bytes:11086739 (10.5 MiB)
          Interrupt:169

    eth1      Link encap:Ethernet  HWaddr 00:25:64:3D:22:4F 
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:64805 errors:0 dropped:0 overruns:0 frame:0
          TX packets:32261 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:91213459 (86.9 MiB)  TX bytes:2096341 (1.9 MiB)
          Interrupt:177
查看bond0工作状态
        #cat /proc/net/bonding/bond0
    Bonding Mode: load balancing (round-robin)
    MII Status: up
    MII Polling Interval (ms): 100
    Up Delay (ms): 0
    Down Delay (ms): 0

    Slave Interface: eth0
    MII Status: up
    Link Failure Count: 0
    Permanent HW addr: 00:25:64:3d:22:4f

    Slave Interface: eth1
    MII Status: up
    Link Failure Count: 0
    Permanent HW addr: 00:25:64:3d:22:50


###########################################################################################################

环境:CentOS6.0 Linux version 2.6.32-71.el6.x86_64,双网卡
配置:
1.新建 bonding.conf 文件 
       #cd /etc/modprobe.d 
       #vi bonding.conf 加入如下内容
       alias bond0 bonding
2.新建 bond0 文件 
       #cd /etc/sysconfig/network-scripts 
       #cp ifcfg-eth0 ifcfg-eth0_backup ---(备份要修改的文件) 
       #cp ifcfg-eth0 ifcfg-bond0 
       #vi ifcfg-bond0 
       DEVICE=bond0  ---(将eth0改为bond0)
       IPADDR=192.168.0.231 
       GATEWAY=192.168.0.1
       NETMASK=255.255.255.0 
       ONBOOT=yes 
       BOOTPROTO=none 
       USERCTL=no 
       BONDING_OPTS="miimon=100 mode=0"
说明: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会认为链路没有问题而继续使用
3.修改 eth0 文件,只保留必须的选项 
       #vi ifcfg-eth0 
       DEVICE=eth0 
       BOOTPROTO=none 
       ONBOOT=yes 
       MASTER=bond0 
       SLAVE=yes 
       USERCTL=no 
  修改 eth1 的文件,同 eth0,只保留必须的选项 
       DEVICE=eth1 
       BOOTPROTO=none 
       ONBOOT=yes 
       MASTER=bond0 
       SLAVE=yes 
       USERCTL=no 
4.修改/etc/rc.local这个文件,在内容最后添加如下一行:
       #ifenslave bond0 eth0 eth1
5.测试结果,重启服务,建议重新启动计算机 
       #service network restart 
       #ifconfig 显示结果如下
       bond0     Link encap:Ethernet  HWaddr 00:25:64:3D:22:4F 
          inet addr:192.168.0.231  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::225:64ff:fe3d:224f/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:130447 errors:0 dropped:0 overruns:0 frame:0
          TX packets:563 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:11985407 (11.4 MiB)  TX bytes:97053 (94.7 KiB)

       eth0      Link encap:Ethernet  HWaddr 00:25:64:3D:22:4F 
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:65219 errors:0 dropped:0 overruns:0 frame:0
          TX packets:284 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5991352 (5.7 MiB)  TX bytes:49778 (48.6 KiB)
          Interrupt:16

       eth1      Link encap:Ethernet  HWaddr 00:25:64:3D:22:4F 
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:65228 errors:0 dropped:0 overruns:0 frame:0
          TX packets:279 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5994055 (5.7 MiB)  TX bytes:47275 (46.1 KiB)
          Interrupt:17
查看bond0工作状态
        #cat /proc/net/bonding/bond0
        Bonding Mode: load balancing (round-robin)
        MII Status: up
        MII Polling Interval (ms): 100
        Up Delay (ms): 0
        Down Delay (ms): 0

        Slave Interface: eth0
        MII Status: up
        Link Failure Count: 0
        Permanent HW addr: 00:25:64:3d:22:4f

        Slave Interface: eth1
        MII Status: up
        Link Failure Count: 0
        Permanent HW addr: 00:25:64:3d:22:50 

PS:重启服务器可能会出现网卡找不到的情况,这是因为centos6.0开始通过udev来管理网卡,具体网卡序号的配置文件在:/etc/udev/rules.d/70-persistent-net.rules文件中,解决办法
#vi /etc/udev/rules.d/70-persistent-net.rules
注释掉bond0的配置,再重启服务器就可以了
 

你可能感兴趣的:(linux,linux,职场,双网卡,休闲)