[运维] CentOS8创建桥接网络

  • Post author:
  • Post category:其他

原文地址

CentOS8创建网桥
bridge-utils软件包在RHEL7.7被弃用了,所以后面版本不能使用brctl命令。
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/7.7_release_notes/deprecated_functionality

使用nmcli

使用nmcli可以完成相同的功能:

1.创建网桥

nmcli conn add type bridge con-name br0 ifname br0

2.配置IP地址

nmcli connection modify br0 ipv4.addresses '192.168.11.8/24' ipv4.gateway '192.168.11.254' ipv4.dns '114.114.114.114' ipv4.method manual

3.为网桥关联物理接口

nmcli conn add type ethernet slave-type bridge con-name br0-ens192  ifname ens192  master br0
nmcli conn up br0

4.关闭以太网卡的connection

nmcli conn down ens192
  1. 配置ens192
sudo cp /etc/sysconfig/network-scripts/ifcfg-ens192 /etc/sysconfig/network-scripts/ifcfg-ens192.bak
## 编辑/etc/sysconfig/network-scripts/ifcfg-ens192
vim /etc/sysconfig/network-scripts/ifcfg-ens192

清空/etc/sysconfig/network-scripts/ifcfg-ens192内容并添加以下内容

DEVICE=ens192
#NM_CONTROLLED=no
ONBOOT=yes
BOOTROTO=none
BRIDGE=br0
  1. 关闭NetworkManager
[root@localhost ~]# systemctl disable NetworkManager

7.查看物理网卡的桥接

[root@localhost ~]# bridge link show
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 100
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 master virbr0 state disabled priority 32 cost 100
7: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master virbr0 state forwarding priority 32 cost 100

如需要恢复配置,执行如下命令。

nmcli conn up ens192
nmcli conn down br0
nmcli conn del br0
nmcli conn del br0-ens192
sudo cp /etc/sysconfig/network-scripts/ifcfg-ens192.bak /etc/sysconfig/network-scripts/ifcfg-ens192
systemctl enble NetworkManager