Linux內核支持網口橋接。它的內核是通過一個虛擬的網橋設備來實現橋接的。虛擬機可以綁定若干個以太網接口設備,從而將他們橋接起來。網橋設備br0綁定eth0,br0作爲一個網橋,同時也是虛擬機的網絡設備,它既可以用作網橋的管理端口,也可以作爲網橋所連接局域網的網關,視具體需求而定。
網橋默認沒有配置
##一.網絡橋接
網橋br0
cd /etc/sysconfig/network-scripts/
在這個網絡配置文件下完成
ls
移動網絡配置文件:
mv ifcfg-br0 ifcfg-enp0s25 /mnt/
編輯文件:
vim ifcfg-enp0s25
DEVICE=enp0s25
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.30
NETMASK=255.255.255.0
reboot
測試:
虛擬機加網卡時,沒有br0
cd /etc/sysconfig/network-scripts/
ls
rm -fr ifcfg-所有
vim ifcfg-enp0s25
DEVICE=enp0s25
ONBOOT=yes
BOOTPROTO=none
BRIDGE=br0
vim ifcfg-br0
DEVICE=br0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.30
NETMASK=255.255.255.0
TYPE=Bridge #真實設備上的接口,通過br0把數據傳到enp0s25網卡上
systemctl restart network
ifconfig (多了br0)
rm -fr ifcfg-br0 ifcfg-enp0s25
mv /mnt/ifcfg-* .
reboot
##二.bond
只支持兩塊網卡
三種工作模式:
(1)模式0(平衡輪循)-輪循策略,所有接口都使用採用輪循方式在所有slave中傳輸封包;任何slave都可以接收
(2)模式1(主被備份)-容錯。一次能使用一個slave接口,但是如果接口出現故障,另一個slave將接替它
(3)模式3(廣播)- 容錯。所有封包都通過所有slave接口廣播
網絡橋接的管理命令
brctl ##橋接管理命令
show ##顯示
addbr ##添加網橋
delbr ##刪除網橋
addif ##添加網橋連接
delif ##刪除網橋連接
brctl show #查看橋接
brctl addbr br0 #添加br0網絡橋接
brctl show
ping 172.25.254.30 #沒有真實鏈接物理設備,不通
ifconfig br0 172.25.254.230 netmask 255.255.255.0 #橋接
nm-connection-editor #刪除eth0
brctl addif br0 eth0 #橋接真實網卡,br0上添加物理接口
brctl show
ping 172.25.254.60
ifconfig br0 down #停掉br0
沒有橋接br0
brctl show
![](
brctl delif br0 eth0 #刪除eth0在br0上的橋接
brctl show
brctl delbr br0 #刪除橋接br0
brctl show
ifconfig
刪除所有網卡
加網卡
systemctl restart NetworkManager
nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.254.230/24 ##bond網絡中添加bond0
nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0 #把eth0添加到bond0中,採用主被工作模式
ifconfig
nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0 #添加網卡eth1到bond0中
測試:
ifconfig eth0 down
ifconfig eth0 up
ifconfig eth1 down
nmcli connection delete eth1
nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0
watch -n 1 cat /proc/net/bonding/bond0 #監控命令
ping 172.25.254.30 #當ifconfig eth0 down表示eth0停掉,此時eth1開始工作
eth1出現問題,nmcli connection delete eth1刪除eth1,在重新添加nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0
可以監控看出誰工作,網絡一直都是通的
nm-connection-editor #有三塊網卡
nmcli connection delete bond0
nmcli connection delete eth0
nmcli connection delete eth1
nm-connection-editor #無網卡
##三.team接口
最多支持八塊網卡
通過nmcli 設定
nmcli connection add con-name team0 type team ifname team0 config '{"runner":{"name":"activebackup"}}' ip4 172.25.254.230/24 #team接口添加team0
ifconfig #team0加上
teamdctl team0 state
nmcli connection add con-name eth0 ifname eth0 team-slave master team0 #添加eth0到team主被工作模式
ping 172.25.254.60
watch -n 1 teamdctl team0 state #可以看出誰工作
nmcli connection add con-name etn1 ifname eth1 team-slave master team0 #添加eth1主被工作模式到team0
ifconfig eth0 down
ifconfig eth0 up
ifconfig eth1 down
ifconfig eth1 up