Ubuntu 22.04.1 LTS
裸机服务器,仅 ssh 访问
使用 nmcli 配置网络
遵循的指南:
https://www.cyberciti.biz/faq/how-to-install-kvm-on-ubuntu-20-04-lts-headless-server/
https://www.answertopia.com/ubuntu/creating-an-ubuntu-kvm-networked-bridge-interface/
我正在设置 KVM 并创建了一个桥接器,以便来宾可以进行外部网络连接。我所遵循的所有指南都让我禁用以太网连接并设置桥接器主设备和从设备,这样就可以了。然而,在重新启动时,以太网连接会返回并阻止桥接器。
重启之前:
root:/$ nmcli connection show
NAME UUID TYPE DEVICE
br0 8e347424-9ffc-4d5c-9fe6-715c23219786 bridge br0
bridge-br0 3dd5d5a9-28d1-48d9-a537-1f6d14528428 ethernet enp3s0
virbr0 348cc1a6-90eb-422e-b994-72daf4811615 bridge virbr0
root:/$ nmcli device
DEVICE TYPE STATE CONNECTION
br0 bridge connected br0
virbr0 bridge connected (externally) virbr0
enp3s0 ethernet connected bridge-br0
lo loopback unmanaged --
重启后:
root:/$ nmcli connection show
NAME UUID TYPE DEVICE
br0 8e347424-9ffc-4d5c-9fe6-715c23219786 bridge br0
enp3s0 5111945c-55bb-4937-ac41-ac25da5140ef ethernet enp3s0
virbr0 3e8ca585-1e43-457d-affd-ccae25eb08f0 bridge virbr0
bridge-br0 3dd5d5a9-28d1-48d9-a537-1f6d14528428 ethernet --
root:/$ nmcli device
DEVICE TYPE STATE CONNECTION
br0 bridge connected br0
virbr0 bridge connected (externally) virbr0
enp3s0 ethernet connected (externally) enp3s0
lo loopback unmanaged --
我可以通过运行此脚本手动修复它:
#!/bin/bash
nmcli con down enp3s0 && nmcli con up br0
但不是通过 (root) cron,上行部分运行,但下行部分不执行任何操作。如果我手动运行 cron 脚本,则两者都可以工作。
我尝试检查自动连接规则,这是它们当前的设置方式。设置这些值后,我已重新启动/重新加载:
root:/$ nmcli -f name,autoconnect con
NAME AUTOCONNECT
br0 yes
enp3s0 no
virbr0 no
bridge-br0 yes
其他注意事项:
root:/$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether d4:5d:64:7c:ff:ad brd ff:ff:ff:ff:ff:ff
inet 89.xx.xx.29/25 brd 89.xx.xx.127 scope global enp3s0
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:f7:54:75 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 4a:42:6a:76:98:ae brd ff:ff:ff:ff:ff:ff
inet 192.168.2.25/24 brd 192.168.2.255 scope global noprefixroute br0
valid_lft forever preferred_lft forever
值得注意的是,br0 状态为 DOWN,但 ping 192.168.2.25 确实有响应。
日记日志:https://tempaste.com/Cow2Mvvhbcv
尝试:在‘/etc/NetworkManager’中的[main]中添加‘no-auto-default=enp3s0’,但这并没有带来任何变化。
我目前的想法是,也许 enp3s0 需要某种配置文件才能不自动启动?也许 cron 无法工作是因为重启时网络尚未完全设置?
如何让桥接器在重启后继续工作?