我想设置一个桥接,以便无头服务器上的客户虚拟机使用 LAN DHCP 而不是 dnsmasq。我遵循了以下说明:https://jamielinux.com/docs/libvirt-networking-handbook/bridged-network.html#bridge-debian。查看ifconfig
结果,它似乎正好给了我所寻找的东西:
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.210 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::4216:7eff:fe63:7516 prefixlen 64 scopeid 0x20<link>
ether 40:16:7e:63:75:16 txqueuelen 1000 (Ethernet)
RX packets 8255 bytes 653898 (653.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 633 bytes 60185 (60.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.195 netmask 255.255.255.0 broadcast 192.168.1.255
ether 40:16:7e:63:75:16 txqueuelen 1000 (Ethernet)
RX packets 42190 bytes 48646124 (48.6 MB)
RX errors 0 dropped 3 overruns 0 frame 0
TX packets 9808 bytes 889965 (889.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 2215 bytes 510180 (510.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2215 bytes 510180 (510.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:7a:ca:5e txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
但是,如果我尝试从另一台计算机 (192.168.1.196) 通过 SSH 连接到我的服务器 (192.168.1.195),则无法连接。从服务器执行 ping 似乎无法到达我的 LAN 上的其他设备,但从服务器执行 ping 到 8.8.8.8 似乎可以正常工作。我的/etc/network/interfaces
文件如下所示(MAC 是我的服务器的 NIC):
iface enp3s0 inet manual
auto br0
iface br0 inet static
# Use the MAC address identified above.
hwaddress ether 40:16:7e:63:75:16
address 192.168.1.210
netmask 255.255.255.0
gateway 192.168.1.1
bridge_ports enp3s0
# If you want to turn on Spanning Tree Protocol, ask your hosting
# provider first as it may conflict with their network.
bridge_stp on
# If STP is off, set to 0. If STP is on, set to 2 (or greater).
bridge_fd 0
我花了两天时间在谷歌上搜索,当服务器出现问题时,我也重新镜像了几次,我想我已经失去理智了...我的服务器是 Ubuntu 18.04.2,除了安装的 libvirt 和 ssh 包外,其余都是原版。我怎样才能让其他网络机器可以访问服务器?
答案1
有时,把事情搁置一两天,不去想它们是有好处的。然后重新开始。最后,建立桥梁似乎相当简单,只需以下两个步骤:
- 更新 /etc/sysctl.conf
取消注释“.net.ipv4.ip_forward=1”行
- 更新 /etc/network/interfaces
对我来说,这就是整个文件。如果你有更多接口,你可能需要进行相应调整。enp3s0 是我的物理接口的 ID。
# ifupdown has been replaced by netplan(5) on this system. See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
# sudo apt install ifupdown
iface enp3s0 inet manual
auto lo
iface lo inet loopback
auto br0
iface br0 inet dhcp
bridge_ports enp3s0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
我在路由器中使用了 IP 地址预留,以确保我的虚拟机始终获得相同的 IP 地址。使用 DHCP 总体上使配置对我来说更容易一些。
再次感谢 RobertRSeattle 和 Doug Smythies 的包容。
答案2
我有一个工作桥断了。我尝试了所有方法。我开始寻找 docker 文件,认为 docker 破坏了我的网络。结果发现,客户机中的网络接口名称发生了变化,enp1s0 变成了 enp7s0。修复了 /etc/netplan yaml,一切都恢复了。