linux網卡綁定

網卡綁定可以將多塊網卡虛擬成一塊網卡,聚合起來工作。網卡綁定需要網卡工作在混雜promisc模

式,並且需要將兩塊網卡的mac地址改成相同。

1,配置bond0

# vi ifcfg-bond0
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
DELAY=0
BOOTPROTO=static
IPADDR=192.168.1.20
NETMASK=255.255.255.0

2,配置網卡加入bond0
# vi ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
 

# vi ifcfg-eth2
DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes

# vi ifcfg-eth3
DEVICE=eth3
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes    


3,在/etc/modules.conf文件中添加如下內容(如果沒有該文件,則新建一個):

alias bond0 bonding
options bond0 miimon=100 mode=0 primary=eth1
其中miimon=100表示每100ms檢查一次鏈路連接狀態,如果不通則會切換物理網卡
mode=1表示主備模式,也就是隻有一塊網卡是active的,只提供失效保護。如果mode=0則是負載均

衡模式的,所有的網卡都是active,還有其他一些模式很少用到
primary=eth1表示主備模式下eth1爲默認的active網卡


4,最後,在/etc/rc.local中加入

modprobe bonding miimon=100 mode=1
重起系統即可生效

5,也可直接執行
#modprobe bonding miimon=100 mode=1
之後
# ifconfig
bond0     Link encap:Ethernet  HWaddr 84:2B:2B:15:4D:BA 
          inet addr:192.168.1.20  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

eth1      Link encap:Ethernet  HWaddr 84:2B:2B:15:4D:BA 
          UP BROADCAST SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
          Interrupt:114 Memory:d8000000-d8012800

eth2      Link encap:Ethernet  HWaddr 84:2B:2B:15:4D:BA 
          UP BROADCAST SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
          Interrupt:122 Memory:da000000-da012800

eth3      Link encap:Ethernet  HWaddr 84:2B:2B:15:4D:BA 
          UP BROADCAST SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
          Interrupt:130 Memory:dc000000-dc012800

6,加bond0到橋
虛擬化環境中經常需要把網卡加到網橋上

# vi ifcfg-virbr1

DEVICE=virbr1
TYPE=Bridge
ONBOOT=yes
DELAY=0
BOOTPROTO=static
IPADDR=192.168.1.20
NETMASK=255.255.255.0

# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BRIDGE=virbr1

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章