跳转至

Rocky 9 nmcli 配置网桥 br0

系统: Rocky Linux 9
网桥名称: br0
物理网卡: eth0


一、环境信息

项目 配置
网桥 IP 172.16.1.24/24
网关 172.16.1.1
DNS 172.16.1.16
物理接口 eth0
STP 关闭

二、备份原配置

Bash
1
2
3
4
5
6
# 查看当前连接
nmcli connection show

# 备份 eth0 配置
cd /etc/NetworkManager/system-connections
cp eth0.nmconnection /root/

三、创建网桥(nmcli 命令)

3.1 创建网桥接口

Bash
nmcli connection add type bridge ifname br0 con-name br0 autoconnect yes

3.2 配置 IP 地址

Bash
1
2
3
4
nmcli connection modify br0 ipv4.addresses 172.16.1.24/24
nmcli connection modify br0 ipv4.gateway 172.16.1.1
nmcli connection modify br0 ipv4.dns "172.16.1.16"
nmcli connection modify br0 ipv4.method manual

3.3 关闭 STP

Bash
nmcli connection modify br0 bridge.stp no

3.4 添加 eth0 为从属接口

Bash
nmcli connection add type bridge-slave ifname eth0 con-name eth0 master br0

四、激活网桥

Bash
# 重新加载配置
nmcli connection reload

# 停用原 eth0
nmcli connection down eth0

# 激活网桥
nmcli connection up br0

# 激活从属接口
nmcli connection up eth0

五、验证配置

Bash
# 查看 IP 地址
ip addr show br0

# 查看网桥状态
bridge link show

# 查看连接状态
nmcli connection show

# 测试网关
ping -c 3 172.16.1.1

# 测试外网
ping -c 3 8.8.8.8

六、查看配置文件

Bash
1
2
3
4
5
# 网桥配置
cat /etc/NetworkManager/system-connections/br0.nmconnection

# 从属网卡配置
cat /etc/NetworkManager/system-connections/eth0.nmconnection

br0.nmconnection 示例

INI
[connection]
id=br0
type=bridge
interface-name=br0
autoconnect=true

[ethernet]

[bridge]
stp=false

[ipv4]
address1=172.16.1.24/24
dns=172.16.1.16;
gateway=172.16.1.1
method=manual

[ipv6]
method=disabled

eth0.nmconnection 示例

INI
[connection]
id=eth0
type=ethernet
interface-name=eth0
autoconnect=true
master=br0
slave-type=bridge

[ethernet]

[ipv4]
method=auto

[ipv6]
method=disabled

七、故障排查

7.1 配置失败,清理重来

Bash
1
2
3
nmcli connection delete br0
nmcli connection delete eth0
nmcli connection reload

7.2 查看网卡物理状态

Bash
ip link show eth0
ethtool eth0 | grep -E "Link|Speed"

7.3 查看网桥信息

Bash
brctl show
bridge link show

八、注意事项

事项 说明
STP 配置 单服务器接交换机,建议关闭 STP
激活顺序 先 br0,后 eth0
文件权限 NetworkManager 要求配置文件权限为 600
交换机端口 如报 Port Violation,需重置交换机端口或克隆原 MAC

九、常用命令速查

Bash
# 查看所有连接
nmcli connection show

# 查看设备状态
nmcli device status

# 重新加载配置
nmcli connection reload

# 激活连接
nmcli connection up <name>

# 停用连接
nmcli connection down <name>

# 删除连接
nmcli connection delete <name>

# 修改连接
nmcli connection modify <name> <key> <value>