1. linux 雙網卡綁定
什麼的linux系統?
sles:
#
vi
/etc/sysconfig/network/ifcfg-bond0
插入如下內容
BOOTPROTO='static'
IPADDR='10.34.81.21'
NETMASK='255.255.255.0'
STARTMODE='onboot'
BONDING_MASTER='yes'
BONDING_MODULE_OPTS='mode=1
miimon=200
use_carrier=1'
BONDING_SLAVE0='eth1'
BONDING_SLAVE1='eth2'
檢查#
/etc/sysconfig/network/
下有沒有eth1、eth2的MAC地址配置,若有,則刪除
啟動雙網卡綁定#
rcnetwork
restart
其中:BONDING_MODULE_OPTS='mode=1
為主備
0為負荷分擔
redhat:
創建一個ifcfg-bond0
#
vi
/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BONDING_OPTS="mode=1
miimon=500"
BOOTPROTO=none
ONBOOT=yes
BROADCAST=192.168.0.255
IPADDR=192.168.0.180
NETMASK=255.255.255.0
NETWORK=192.168.0.0
USERCTL=no
其中:BONDING_OPTS="mode=1
為主備
0為負荷分擔
修改/etc/sysconfig/ifcfg-ethX
這里說的ethX指要加入綁定網卡的名稱,本例中是eth0、eth1。
#
vi
/etc/sysconfig/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
#
vi
/etc/sysconfig/ifcfg-eth1
DEVICE=eth1BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
配置/etc/modprobe.conf,添加alias
bond0
bonding
#
vi
/etc/modprobe.conf
alias
eth0
pcnet32
alias
eth1
pcnet32
alias
scsi_hostadapter
mptbase
alias
scsi_hostadapter1
mptspi
alias
bond0
bonding
重啟網路服務
#service
network
restart
2. linux雙網卡綁定有幾種模式
Linux網卡綁定mode共有七種(0~6) bond0、bond1、bond2、bond3、bond4、bond5、bond6
常用的有三種
mode=0:平衡負載模式,有自動備援,但需要」Switch」支援及設定。
mode=1:自動備援模式,其中一條線若斷線,其他線路將會自動備援。
mode=6:平衡負載模式,有自動備援,不必」Switch」支援及設定。
3. Linux 網卡綁定什麼作用
首先檢測系統是否安裝開啟NetworkManager服務,在root 用戶下輸入rpm -qa NetworkManager 如命令行下方出現NetworkManager-0.8.1-33.el6.x86_64名字類似的名字證明已經安裝,命令行輸入service NetworkManager status 查看NetworkManager是否為開啟狀態,默認為開啟,如果為開啟狀態請輸入chkconfig NetworkManager off 關閉服務。關閉後我們就可以正常的做網卡綁定配置了。切記在網卡綁定之前一定要關閉這個服務否則綁定網卡會報錯,請確保如圖示紅色框起來的狀態,否則綁定不會成功。
rhel linux 網卡綁定
第一組網卡綁定配置進入 /etc/sysconfig/network-scripts/目錄,首先cp 將eth0或者em1名字的網卡配置文件復制一份(其他網卡也同樣備份一份),我保存到當前目錄 命名為ifcfg-em1.bak 已避免綁定失敗無法回滾。備份好在當前網卡配置信息,直接vi ifcfg-bond0(這個文件在網卡沒有綁定之前一般不存在我們直接vi建立就好了)將下面參數直接粘貼到band0文件裡面。之後配置兩塊網卡的參數。
下面為bond0參數
EVICE=bond0
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.28.102 (IP地址根據自的實際情況填寫)
NETMASK=255.255.255.0 (掩碼根據自的實際情況填寫)
GATEWAY=192.168.28.254 (網關自己網路的網關)
USERCTL=no
em1網卡參數
vi ifcfg-em1 進入em1配置,將裡面的配置清空,粘貼如下參數,rhel系統安裝到dell 伺服器會將網卡ID eth0變成em1,這里的網卡id需要根據系統裡面的文件確定,有些是eth*的id。我這里就是em1的id,參數如下;
DEVICE=em1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
USERCTL=no
保存退出,在vi ifcfg-em2 進入em2配置,直接清空配置,粘貼如下參數。
DEVICE=em2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
USERCTL=no
rhel linux 網卡綁定
rhel linux 網卡綁定
rhel linux 網卡綁定
通過上一步bond0 和em1 em2的參數配置,網卡綁定修改參數還差一步就完成了,請在/etc/modprobe.conf文件中添加如下腳本,如果沒有modprobe.conf文件看直接vi 一個填入下面的代碼既可。
modprobe.conf文件添加的腳本如下
alias eth0 pcnet32
alias eth1 pcnet32
alias bond0 bonding
options bond0 miimon=100 mode=0(配置模式這里配置為mode=0負載均衡模式0,mode參數為模式類型,具體請參考相關模式資料。miimon為監聽時間,我設置100為0.1毫秒)
請將以上4行添加保存。到此第一組網卡綁定參數設置已經完成,如是多個網卡綁定為一組方法相同只需要將配置參數復制粘貼到相關網卡配置文件既可只需修改DEVICE將網卡id更換既可。
rhel linux 網卡綁定
第二組網卡配置與第一組基本相同,只不過就是修改一些IP地址和網關,一般的網路只有一個網關,我們在第一組配置了網關,在第二組我們就不用在配置網關了。當前目錄下新建bond1,直接vi ifcfg-bond1將下面的bond1參數粘貼過來。將這兩個保存即可。網卡參數配置修改,直接將網卡現有配置刪除,vi ifcfg-em3/eth4 進入網卡配置參數修改,刪除網卡現有的配置參數直接粘貼以下腳本。
下面bond1參數
DEVICE=bond1
BOOTPROTO=none
ONBOOT=yes
IPADDR=172.18.99.18 (IP地址根據自的實際情況填寫)
NETMASK=255.255.255.0 (掩碼根據自的實際情況填寫)
USERCTL=no
網卡配置參數
DEVICE=eth3
BOOTPROTO=none
ONBOOT=yes
MASTER=bond1 (掩碼寫bond1)
USERCTL=no
DEVICE=eth4
BOOTPROTO=none
ONBOOT=yes
MASTER=bond1 (掩碼寫bond1)
USERCTL=no
rhel linux 網卡綁定
通過上一步bond1 和em3 em4的參數配置,網卡綁定修改參數還差一步就完成了,請在/etc/modprobe.conf文件中添加如下腳本,之前的bond0配置文件也配置過,直接在bond0下面添加既可,
modprobe.conf文件添加的腳本如下
alias eth3 pcnet32
alias eth4 pcnet32
alias bond1 bonding
options bond0 miimon=100 mode=0(配置模式這里配置為mode=0負載均衡模式0,mode參數為模式類型,具體請參考相關模式資料。miimon為監聽時間,我設置100為0.1毫秒)
請將以上4行添加保存。到此第二組網卡綁定參數設置已經完成,如是多個網卡綁定為一組方法相同只需要將配置參數復制粘貼到相關網卡配置文件既可只需修改DEVICE將網卡id更換既可。
rhel linux 網卡綁定
通過以上配置,兩組網卡配置基本完成,現在我們重啟網路服務 輸入命令
service network restart 等待從其完成,現在網卡配置還沒有生效,請輸入以下兩行代碼是網卡綁定生效;
ifenslave bond0 em1 em2
ifenslave bond1 em3 em4
為了更好的利用系統資源,我們還需要將生效過程開機自動啟動,需要在/etc/rc.d/rc.local目錄下將這兩行代碼添加進去,下次重啟伺服器就會自動生效,否者還需要手動生效。
配置全部完成,只剩下檢測了,現在我需要用ifconfig 來檢測一下綁定信息如圖所示,bond0下的em1 em2 的mac地址全部相同證明成功了。bond1也是一個道理,這里我缺少bond1的圖片,正常ifconfig是全部都會有的只要確定bond1和em3 em4的mac地址相同基本就是正常。
rhel linux 網卡綁定
4. RedHat Linux 7.4中多網卡綁定問題
禁用預設的NetworkManager服務,啟用network服務
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service
systemctl enable network.service
systemctl restart network.service
5. Linux系統雙網卡綁定配置教程
系統版本
[root@ ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@ ~]# uname -r
2.6.32-642.6.1.el6.x86_64
網卡說明
eth0 192.168.1.8(伺服器外網卡)
eth1 伺服器網卡(內網)
eth2 伺服器網卡(內網)
[root@ ~]# /etc/init.d/iptables stop
[root@ ~]# chkconfig iptables off
關閉selinux
[root@ ~]#setenforce 0
[root@ ~]#sed -i 『s/SELINUX=enforcing/SELINUX=disabled/『 /etc/selinux/config
禁用NetworkManager
[root@ ~]# /etc/init.d/NetworkManager stop
Stopping NetworkManager daemon: [ OK ]
[root@ ~]# chkconfig NetworkManager off
[root@ ~]# /etc/init.d/network restart
雙網卡綁定配置過程
[root@ ~]# cd /etc/sysconfig/network-scripts/
編輯eth1網卡
[root@ network-scripts]# cat >ifcfg-eth1 <> DEVICE=eth1
> ONBOOT=yes
> BOOTPROTO=none
> USERCTL=no
> MASTER=bind0
> EOF
編輯eth2網卡
[root@ network-scripts]# cat >ifcfg-eth2
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bind0
EOF
編輯bind0網卡
[root@ network-scripts]# cat >ifcfg-bind0 <> DEVICE=bind0
> TYPE=Ethernet
> ONBOOT=yes
> BOOTPROTO=none
> IPADDR=10.0.0.8
> NETMASK=255.255.255.0
> GATEWAY=10.0.0.254
> IPV6INIT=no
> USERCTL=no
> EOF
配置bond參數
[root@ network-scripts]# cat >/etc/modprobe.conf <> alias bind0 bonding
> options bind0 miimon=100 mode=6
> EOF
加入開機自啟動(/etc/rc.local)
[root@ network-scripts]# cat >>/etc/rc.local <> ifenslave bind0 eth1 eth2
> EOF
重啟網路服務
[root@LVS-2 network-scripts]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down interface eth2: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bind0: WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
Determining if ip address 10.0.0.8 is already in use for device bind0..[ OK ]
Bringing up interface eth0: Determining if ip address 192.168.1.8 is already in use for device eth0... [ OK ]
Bringing up interface eth1: RTNETLINK answers: File exists [ OK ]
Bringing up interface eth2: RTNETLINK answers: File exists [ OK ]
配置使綁定立即生效
[root@LVS-2 network-scripts]# ifenslave bind0 eth1 eth2
測試聯通
[root@LVS-2 network-scripts]# ping 10.0.0.8
PING 10.0.0.8 (10.0.0.8) 56(84) bytes of data.
64 bytes from 10.0.0.8: icmp_seq=1 ttl=64 time=0.089 ms
64 bytes from 10.0.0.8: icmp_seq=2 ttl=64 time=0.046 ms
^C
--- 10.0.0.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1921ms
rtt min/avg/max/mdev = 0.046/0.067/0.089/0.023 ms
此時會發現系統多一個網卡
[root@LVS-2 network-scripts]# ifconfig bind0
bind0
Link encap:Ethernet HWaddr 00:0C:29:CC:9B:5
inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fecc:9b55/64 Scope:LinkUP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:151 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11826 (11.5 KiB) TX bytes:258 (258.0 b)