Linux下快速設定ip bond

來源:互聯網
上載者:User

Linux下快速設定ip bond

在電腦網路普及的初期,很多OS系統都使用的為單網卡方式,即一個網卡使用一個IP地址。隨著網路要求的不斷提高,我們可以對多個網卡進行綁定彙總當一個邏輯網路介面來使用,從而大幅提升伺服器的網路吞吐(I/O),同時也可以根據不同的情境和需求來設定其繫結模式。本文簡要描述一下其配置過程。

1. 編輯ifcfg-bond0檔案
###本文示範環境CentOS release 5.11,對eth0以及eth1進行bond
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0             
BOOTPROTO=static
IPADDR=192.168.9.33     
NETMASK=255.255.255.0
BROADCAST=192.168.9.255
GATEWAY=192.168.9.250
ONBOOT=yes
TYPE=Ethernet

2. 編輯eth0、eth1檔案
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
### Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=none
HWADDR=xx:xx:xx:xx:xx:xx  #此處為對應的mac地址
ONBOOT=yes
MASTER=bond0
SLAVE=yes

# vi /etc/sysconfig/network-scripts/ifcfg-eth1
### Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth1
BOOTPROTO=none
HWADDR=xx:xx:xx:xx:xx:xx
ONBOOT=yes
HOTPLUG=no
MASTER=bond0
SLAVE=yes

3. 編輯modprobe.conf檔案
# vi /etc/modprobe.conf
添加:
alias bond0 bonding
options bond0 miimon=100 mode=0

說明:
1).miimon=100 用來設定鏈路監測的間隔時間。即每100ms監測一次鏈路狀態。bonding只監測主機與交換器之間鏈路。如果交換器出去的鏈路出問題而本身沒有問題,那麼bonding認為鏈路沒有問題而繼續使用。
2).mode=1 表示提供冗餘功能。除此之外還可以為0、2、3,共四種模式。0表示負載平衡
3).更詳細的可參考:深度分析Linux下雙網卡綁定七種模式 

4. 重啟網路
# service network restart

5. 驗證
通過其它機器ping 綁定的ip,ping的過程中拔掉eth0或eth1網線,確認網路是否持續正常

###參考如下的驗證為啟動bond後的結果
# less /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0-2 (October 7, 2008)

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
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 44:a8:42:0b:a7:a5

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 44:a8:42:0b:a7:a6

###查看當前主機的IP配置資訊
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 44:a8:42:0b:a7:a5 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 44:a8:42:0b:a7:a5 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
    link/ether 44:a8:42:0b:a7:a7 brd ff:ff:ff:ff:ff:ff
5: eth3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 44:a8:42:0b:a7:a8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.15/24 brd 192.168.10.255 scope global eth3
6: sit0: <NOARP> mtu 1480 qdisc noop
    link/sit 0.0.0.0 brd 0.0.0.0
7: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue
    link/ether 44:a8:42:0b:a7:a5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.9.33/24 brd 192.168.9.255 scope global bond0
    inet6 fe80::46a8:42ff:fe0b:a7a5/64 scope link
      valid_lft forever preferred_lft forever

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.