网桥相当于一台交换机
一般用在虚拟机上面
配置网桥:
创建网桥:
[root@foundation0 ~]# nmcli connection add type bridge con-name br1 ifname br1
Connection 'br0' (feab4b70-6e01-4451-929d-717aaea64371) successfully added.
创建网桥的端口:
[root@foundation0 network-scripts]# nmcli connection add type bridge-slave con-name br1-port1 ifname eno100663872 master br1
Connection 'br1-port1' (60e61b80-8492-4e53-8660-1955e03b8f9c) successfully added.
[root@foundation0 network-scripts]# nmcli connection add type bridge-slave con-name br1-port2 ifname eno117441096 master br1
Connection 'br1-port2' (fa48d8d5-d860-42ee-b70e-a4d56a5fd04d) successfully added.
为网桥配置IP地址:
[root@foundation0 network-scripts]# nmcli connection modify br1 ipv4.addresses "192.168.2.68/16"
配置为手动
[root@foundation0 network-scripts]# nmcli connection modify br1 ipv4.method manual
断开并重新启动br1
[root@foundation0 network-scripts]# nmcli device disconnect br1
[root@foundation0 network-scripts]# nmcli connection up br1
在/etc/sysconfig/network-scripts/ifcfg-*下查看已配置网桥的配置文件:
[root@foundation0 network-scripts]# cat ifcfg-br1
DEVICE=br1
STP=yes
TYPE=Bridge
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=br1
UUID=ad0354a6-9a86-4d46-ae3a-70a385292bc6
ONBOOT=yes
IPADDR0=192.168.2.68
PREFIX0=16
BRIDGING_OPTS=priority=32768
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
[root@foundation0 network-scripts]# cat ifcfg-br1-port1
TYPE=Ethernet
NAME=br1-port1
UUID=60e61b80-8492-4e53-8660-1955e03b8f9c
DEVICE=eno100663872
ONBOOT=yes
BRIDGE=br1
[root@foundation0 network-scripts]# cat ifcfg-br1-port2
TYPE=Ethernet
NAME=br1-port2
UUID=fa48d8d5-d860-42ee-b70e-a4d56a5fd04d
DEVICE=eno117441096
ONBOOT=yes
BRIDGE=br1
通过brctl查看网桥的创建情况:
[root@foundation0 network-scripts]# brctl show
bridge namebridge idSTP enabledinterfaces
br08000.fe54000000fenovnet0
br18000.000c2906a458yeseno100663872
eno117441096
virbr08000.000000000000yes
virbr18000.000000000000yes
配置链路聚合和桥接:
创建链路聚合:
nmcli connection add type team con-name team0 ifname team0
nmcli connection add type team-slave con-name team0-port1 ifname eno100663872 master team0
nmcli connection add type team-slave con-name team0-port2 ifname eno117441096 master team0
nmcli connection show
nmcli connection modify team0 team.config '{"runner":{"name":"activebackup"}}'
重启team0时,要端口接口先启动,team0才能启动。否则team0启动不了,报如下错误:
[root@foundation0 network-scripts]# nmcli connection up team0
Error: Device 'team0' is waiting for slaves before proceeding with activation.
正确的启动方式:
[root@foundation0 network-scripts]# nmcli connection up team0-port2
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/20)
[root@foundation0 network-scripts]# nmcli connection up team0-port1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/21)
[root@foundation0 network-scripts]# nmcli connection up team0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/22)
查看配置是否正确:
[root@foundation0 network-scripts]# teamdctl team0 state
setup:
runner: activebackup
ports:
eno100663872
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
eno117441096
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
runner:
active port: eno117441096
断开team0,关闭NetworkManager服务:
[root@foundation0 network-scripts]# nmcli device dis team0
[root@foundation0 network-scripts]# systemctl stop NetworkManager
修改ifcfg-team0配置文件:
[root@foundation0 network-scripts]# vim ifcfg-team0
DEVICE=team0
DEVICETYPE=Team
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=team0
UUID=8d36a40b-a4ab-43e9-8efc-658640a547ea
ONBOOT=yes
TEAM_CONFIG="{\"runner\":{\"name\":\"activebackup\"}}"
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
BRIDGE=brteam0
BRIDGE=brteam0#添加以上变量,brteam0是将要创建的网桥的名称
修改组端口配置文件如下:
[root@foundation0 network-scripts]# cat ifcfg-team0-port1
NAME=team0-port1
UUID=652cd19b-9b05-42a0-ad81-9bf67c5eaf9c
DEVICE=eno100663872
ONBOOT=yes
TEAM_MASTER=team0
DEVICETYPE=TeamPort
[root@foundation0 network-scripts]# cat ifcfg-team0-port2
NAME=team0-port2
UUID=e14246a6-3f0f-4551-b55d-140b3d68595e
DEVICE=eno117441096
ONBOOT=yes
TEAM_MASTER=team0
DEVICETYPE=TeamPort
创建网桥ifcfg-brteam0配置文件:
[root@foundation0 network-scripts]# cat ifcfg-brteam0
DEVICE=brteam0
ONBOOT=yes
TYPE=Bridge
IPADDR0=192.168.2.69
PREFIX=16
重置网络以启动新网桥brteam0并重新激活team0接口
Systemctl restart network
重新启动系统后查看配置是否正常:
[root@foundation0 network-scripts]# brctl show
bridge namebridge idSTP enabledinterfaces
br08000.fe54000000fenovnet0
brteam08000.000c2906a458noteam0
virbr08000.000000000000yes
virbr18000.000000000000yes
物理网卡的MAC 地址与网桥的MAC地址一样
网桥的MAC地址会取最后一个真实网卡的MAC地址:
[root@desktop ~]# ifconfig
br0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.25.0.200 netmask 255.255.255.0 broadcast 172.25.0.255
ether 52:54:00:00:00:0a txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.0.10 netmask 255.255.255.0 broadcast 172.25.0.255
inet6 fe80::5054:ff:feb3:2055 prefixlen 64 scopeid 0x20<link>
inet6 2001:db8:0:1:c0::206 prefixlen 64 scopeid 0x0<global>
ether 52:54:00:b3:20:55 txqueuelen 1000 (Ethernet)
RX packets 1326 bytes 117780 (115.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 937 bytes 113146 (110.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:de:1b:43 txqueuelen 1000 (Ethernet)
RX packets 408 bytes 56854 (55.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 45 bytes 4895 (4.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:00:00:0a txqueuelen 1000 (Ethernet)
RX packets 615 bytes 84535 (82.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 32 bytes 4217 (4.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
查看网桥关联的物理网卡接口:
[root@desktop ~]# nmcli connection show
NAME UUID TYPE DEVICE
eth1 f4bb71b4-3cbe-4d19-803a-9a990a3672f6 802-3-ethernet -- #源配置文件会disconnect
System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
eth2 93cbf803-f523-4091-b21a-c14beca6813d 802-3-ethernet -- #源配置文件会disconnect
br0-port1 1a1569ca-2146-4089-abfc-5d9b2164a3e4 802-3-ethernet eth2
br0-port0 5ed86ad3-c83b-4880-a0a9-9437122d66f0 802-3-ethernet eth1
br0 223ff88c-569e-47e8-b781-e495a1bac415 bridge br0
生成的配置文件:
[root@desktop network-scripts]# cat ifcfg-br0
DEVICE=br0
STP=yes
BRIDGING_OPTS=priority=32768
TYPE=Bridge
BOOTPROTO=none
IPADDR0=172.25.0.200
PREFIX0=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=br0
UUID=223ff88c-569e-47e8-b781-e495a1bac415
ONBOOT=yes
[root@desktop network-scripts]# cat ifcfg-br0-port0
TYPE=Ethernet
NAME=br0-port0
UUID=5ed86ad3-c83b-4880-a0a9-9437122d66f0
DEVICE=eth1
ONBOOT=yes
BRIDGE=br0
[root@desktop network-scripts]# cat ifcfg-br0-port1
TYPE=Ethernet
NAME=br0-port1
UUID=1a1569ca-2146-4089-abfc-5d9b2164a3e4
DEVICE=eth2
ONBOOT=yes
BRIDGE=br0