nmcli -f NAME,DEVICE,TYPE,STATE connection show
nmcli -f ipv4.method,ipv4.addresses,ipv4.gateway,ipv4.dns connection show "<existing profile name>"
创建承载相同静态 IP 的网桥(或在 br0 上用 ipv4.method auto 走 DHCP),然后挂接网卡作为网桥端口,再禁用旧配置以免它抢回网卡:
# 1. Create bridge br0 with the host's IP configsudo nmcli connection add type bridge ifname br0 con-name br0 \
ipv4.method manual ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 ipv4.dns 192.168.1.1 \
bridge.stp no
# 2. Attach the physical NIC as a bridge portsudo nmcli connection add type bridge-slave ifname eth0 con-name br0-port-eth0 master br0
# 3. Stop the old profile from auto-activatingsudo nmcli connection modify "<existing profile name>" connection.autoconnect no
# 4. Switch over (brief link interruption; do this from the local console# or accept the drop if connected remotely)sudo nmcli connection up br0
sudo nmcli connection down "<existing profile name>"
两个连接都会持久化,重启后依然有效。回滚方法:nmcli connection up "<existing profile name>" 并恢复 connection.autoconnect yes。
方法 2:ifupdown(/etc/network/interfaces)
/etc/network/interfaces 示例:
# Physical NIC — manual mode, no IP (managed by bridge)auto eth0
iface eth0 inet manual
pre-up ip link set$IFACE up
post-down ip link set$IFACE down
# Bridge br0 — static IP, bridges eth0auto br0
iface br0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
bridge_ports eth0
bridge_stp off
bridge_fd 0 bridge_maxwait 0