Linux 雙網卡綁定及Bridge


Linux 雙網卡綁定及Bridge

一、橋接綁定介紹

linux操作系統下雙網卡綁定有七種模式。現在一般的企業都會使用雙網卡接入,這樣既能添加網絡帶寬,同時又能做相應的冗余,可以說是好處多多。而一般企業都會使用linux操作系統下自帶的網卡綁定模式,當然現在網卡產商也會出一些針對windows操作系統網卡管理軟件來做網卡綁定(windows操作系統沒有網卡綁定功能 需要第三方支持),一共有其中方式,其中比較長用的是0/1/6:

1:網卡綁定案例,先做綁定,然后再把綁定后的網卡配置成橋接:

1.1:第一組配置,將eth1和eth5綁定為bond0:

1.1.1:先創建bond0配置那文件步驟及內容如下:

[root@linux-host1 ~]# cd /etc/sysconfig/network-scripts/
[root@linux-host1 network-scripts]# cp ifcfg-eth0   ifcfg-bond0
[root@linux-host1 network-scripts]# cat ifcfg-bond0 #內容如下:
BOOTPROTO=static
NAME=bond0
DEVICE=bond0
ONBOOT=yes
BONDING_MASTER=yes
BONDING_OPTS="mode=1 miimon=100" #指定綁定類型為1及鏈路狀態監測間隔時間
BRIDGE=br0 #橋接到br0

1.1.2:配置br0:

TYPE=Bridge
BOOTPROTO=static
IPV4_FAILURE_FATAL=no
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=X.X.X.X
NETMASK=255.255.255.0
GATEWAY=X.X.X.X

1.1.3:eth1配置:

[root@linux-host1 network-scripts]# vim ifcfg-eth1
BOOTPROTO=static
NAME=eth1
DEVICE=eth1
ONBOOT=yes
NM_CONTROLLED=no
MASTER=bond0
USERCTL=no
SLAVE=yes

1.1.4:eth5的配置:

[root@linux-host1 network-scripts]# cp ifcfg-eth1  ifcfg-eth5
[root@linux-host1 network-scripts]# vim ifcfg-eth5
BOOTPROTO=static
NAME=eth5
DEVICE=eth5
ONBOOT=yes
NM_CONTROLLED=no
MASTER=bond0
USERCTL=no
SLAVE=yes

1.1.5:重啟網絡服務:

[root@linux-host1 network-scripts]# systemctl  restart network

1.1.6:驗證網絡是否正常:

[root@linux-host1 network-scripts]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.125) 56(84) bytes of data.
64 bytes from 61.135.169.125: icmp_seq=1 ttl=128 time=6.17 ms
64 bytes from 61.135.169.125: icmp_seq=2 ttl=128 time=10.3 ms
64 bytes from 61.135.169.125: icmp_seq=3 ttl=128 time=5.36 ms
64 bytes from 61.135.169.125: icmp_seq=4 ttl=128 time=6.74 ms
64 bytes from 61.135.169.125: icmp_seq=5 ttl=128 time=5.71 ms

1.1.:6:可以驗證當前是綁定在哪一塊網卡上的:

[root@linux-host1 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1 #備份鏈路網卡
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 18:66:da:f3:34:e5
Slave queue ID: 0

Slave Interface: eth5
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0a:f7:99:ba:d1
Slave queue ID: 0

1.2:第二組配置,將eth2和eth6綁定為bond1:

1.2.1:創建bond1配置文件:

[root@linux-host1 network-scripts]# cp ifcfg-bond0  ifcfg-bond1
[root@linux-host1 network-scripts]# vim ifcfg-bond1
BOOTPROTO=static
NAME=bond1
DEVICE=bond1
TYPE=Bond
BONDING_MASTER=yes
BOOTPROTO=static
NAME=bond1
ONBOOT=yes
BONDING_OPTS="mode=1 miimon=100"
BRIDGE=br1

1.2.2:配置br1,綁定到br1為僅主機模式時,不需要DNS1和網關:

TYPE=Bridge
BOOTPROTO=static
IPV4_FAILURE_FATAL=no
NAME=br1
DEVICE=br1
ONBOOT=yes
IPADDR=X.X.X.X
NETMASK=255.255.255.0

1.2.3:eth2的配置:

[root@linux-host1 network-scripts]# vim ifcfg-eth2
BOOTPROTO=static
NAME=eth2
DEVICE=eth2
ONBOOT=yes
NM_CONTROLLED=no
MASTER=bond1
USERCTL=no
SLAVE=yes

1.2.4:eth6的配置:

[root@linux-host1 network-scripts]# vim ifcfg-eth6
BOOTPROTO=static
NAME=eth6
DEVICE=eth6
ONBOOT=yes
NM_CONTROLLED=no
MASTER=bond1
USERCTL=no
SLAVE=yes

1.2.5:重啟網絡服務:

[root@linux-host1 network-scripts]# systemctl  restart network

1.2.6:測試內網網絡是否正常:

[root@linux-host1 network-scripts]# ping 192.168.20.12
PING 192.168.20.12 (192.168.20.12) 56(84) bytes of data.
64 bytes from 192.168.20.12: icmp_seq=1 ttl=64 time=1.86 ms
64 bytes from 192.168.20.12: icmp_seq=2 ttl=64 time=0.570 ms
64 bytes from 192.168.20.12: icmp_seq=3 ttl=64 time=0.410 ms

1.3:設置開機啟動:

[root@linux-host1 network-scripts]# vim /etc/rc.d/rc.local
ifenslave eth1 eth5
ifenslave eth2 eth6
[root@linux-host1 network-scripts]# chmod  a+x /etc/rc.d/rc.local 

1.4:重啟系統后驗證網絡

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM