方法一:通过nmcli命令创建
[root@sre01 ~]# nmcli connection add type bridge con-name br0 ifname br0
Connection 'br0' (cf1064f0-9b88-430f-988a-c4917b51bc21) successfully added.
[root@sre01 ~]# nmcli connection up br0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/24)
[root@sre01 ~]# nmcli connection add type bridge-slave con-name br0-port0 ifname ens37 master br0
Connection 'br0-port0' (47402eed-b0b2-4f4f-b1c8-92919c5f319a) successfully added.
[root@sre01 ~]# nmcli connection add type bridge-slave con-name br0-port1 ifname ens38 master br0
Connection 'br0-port1' (e25340ff-157c-4b58-b53a-34e0d75a811e) successfully added.
[root@sre01 ~]# nmcli connection up br0-port0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/25)
[root@sre01 ~]# nmcli connection up br0-port1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/26)
[root@sre01 ~]#
[root@sre01 ~]#
[root@sre01 ~]# nmcli connection
NAME UUID TYPE DEVICE
ens33 7791cb1b-8774-49e8-8eaa-fa131ab6c509 ethernet ens33
br0 cf1064f0-9b88-430f-988a-c4917b51bc21 bridge br0
demo 83e8c326-356c-46e6-b83e-bdef791c5eb7 ethernet ens36
br0-port0 47402eed-b0b2-4f4f-b1c8-92919c5f319a ethernet ens37
br0-port1 e25340ff-157c-4b58-b53a-34e0d75a811e ethernet ens38
[root@sre01 ~]# nmcli dev show br0
GENERAL.DEVICE: br0
GENERAL.TYPE: bridge
GENERAL.HWADDR: 00:0C:29:C0:78:E5
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: br0
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/24
IP4.ADDRESS[1]: 172.16.156.129/24
IP4.GATEWAY: --
IP4.ROUTE[1]: dst = 172.16.156.0/24, nh = 0.0.0.0, mt = 425
IP4.DNS[1]: 172.16.156.1
IP4.DOMAIN[1]: localdomain
IP6.ADDRESS[1]: fe80::630f:27cc:83c1:e20f/64
IP6.GATEWAY: --
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 425
IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255
[root@sre01 ~]# bridge link show
4: ens37 state UP : <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 100
5: ens38 state UP : <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 100
[root@sre01 ~]# ip link show master br0
4: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:c0:78:e5 brd ff:ff:ff:ff:ff:ff
5: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:c0:78:ef brd ff:ff:ff:ff:ff:ff
删除网桥
[root@sre01 ~]# nmcli connection down br0
Connection 'br0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/24)
[root@sre01 ~]# nmcli connection delete br0
Connection 'br0' (cf1064f0-9b88-430f-988a-c4917b51bc21) successfully deleted.
[root@sre01 ~]# nmcli connection
NAME UUID TYPE DEVICE
ens33 7791cb1b-8774-49e8-8eaa-fa131ab6c509 ethernet ens33
demo 83e8c326-356c-46e6-b83e-bdef791c5eb7 ethernet ens36
Wired connection 1 4b15b5a3-1649-3890-ad4e-66b4b5b52933 ethernet ens37
Wired connection 2 d2f61a05-feb5-3967-9c26-7f86c551f1ac ethernet ens38
br0-port0 47402eed-b0b2-4f4f-b1c8-92919c5f319a ethernet --
br0-port1 e25340ff-157c-4b58-b53a-34e0d75a811e ethernet --
方法二:通过brctl命令
[root@sre01 ~]# yum install bridge-utils
[root@sre01 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29c078e5 yes ens37
ens38
[root@sre01 ~]# brctl showmacs br0
port no mac addr is local? ageing timer
1 00:0c:29:c0:78:e5 yes 0.00
1 00:0c:29:c0:78:e5 yes 0.00
2 00:0c:29:c0:78:ef yes 0.00
2 00:0c:29:c0:78:ef yes 0.00
创建新网桥
[root@sre01 ~]# brctl addbr br1
[root@sre01 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29c078e5 yes ens37
ens38
br1 8000.000000000000 no
[root@sre01 ~]# ifconfig br1 up
从旧网桥删除接口
[root@sre01 ~]# brctl delif br0 ens37
[root@sre01 ~]# brctl delif br0 ens38
[root@sre01 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 yes
br1 8000.000000000000 no
给新网桥添加接口
[root@sre01 ~]# brctl addif br1 ens38
[root@sre01 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 yes
br1 8000.000c29c078ef no ens38
[root@sre01 ~]# brctl addif br1 ens37
[root@sre01 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 yes
br1 8000.000c29c078e5 no ens37
ens38
[root@sre01 ~]#
为网桥开启stp生成树协议
[root@sre01 ~]# brctl stp br1 on
[root@sre01 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 yes
br1 8000.000c29c078e5 yes ens37
ens38