linux系統中將多塊網卡虛擬成爲一塊網卡,以提高網絡的穩定性,增加服務器的可靠性,可爲用戶提供不間斷的網絡服務稱之爲高級網絡配置技術,下面介紹一下bond和team兩種網絡配置步驟及效果:
1.bond網絡配置
首先,添加兩塊網卡,如圖所示,eth0和eth1:
nmcli connection add type bond con-name bond0 ifname bond0 mode active-backup ip4 172.25.254.221/24 創建ip爲172.25.
254.221 子網掩碼爲24的bond0 然後輸入ifconfig命令查看詳細信息:
雖然已經有了ip,但是並不能ping通ip爲172.25.254.88的同網段主機,這是因爲我們還沒有將網卡添加到裏面:
先用命令 watch -n 1 cat /proc/net/bonding/bond0 監控bong0的信息:
然後將一塊網卡eth0添加到裏面:
nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0
然後再看bond0的信息,可以看到eth0已經添加到了bond0裏面並開始工作:
這時,也可以ping通ip爲172.25.254.88的主機了:
然後將第二塊網卡eth1添加進去:
nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0
bond的配置就完成了,之所以要添加兩塊網卡,是爲了提升網絡的穩定和可靠性
然後讓其中一塊網卡eth0停止工作,另一塊網卡eth1就會頂替eth0繼續工作,網絡並不會受到影響:
ifconfig eth0 down
網絡依然是正常的:
繼續讓eth1停止工作,ifconfig eth1 down
可以看到兩塊網卡都有down的標示:
再看網絡已經不能使用了:
然後,刪除eth0,eth1和bond0: ifconfig查看已經沒有bond0了:
2.team網絡配置
team網絡配置的功能和bond功能類似,只是在負載上比bond網絡配置要均衡一些
首先也是需要兩塊網卡,用做bond網絡配置的網卡繼續演示:
nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}' ip4 172.25.254.221/24
創建名爲team0的網絡配置,ifconfig查看:
同樣,爲了看的更加清除,在添加網卡之前,用watch命令監控team0的信息:
watch -n 1 teamdctl team0 state
添加eth0到team0中:
nmcli connection add con-name eth0 ifname eth0 type team-slave master team0
eth0已經添加到team0中,並開始工作:
此時,網絡也可以使用了:
將eth1也添加進去:
nmcli connection add con-name eth1 ifname eth1 type team-slave master team0
ifconfig eth0 down 讓eth0停止工作,eth1也會和bong0一樣馬上頂替eth0繼續工作,而不影響網絡使用:
ifconfig eth1 down 讓eth1也停止工作,然後網絡也就不能使用了:
然後和刪除bond0時一樣,用nmcli命令刪除eth0,eth1和team0:
以上便是bond和team兩種高級網絡配置的創建與刪除。