我有一台新的专用服务器并在其上安装了 KVM。我创建了一个虚拟机,但在管理该虚拟机的公共 IP 时遇到了一些问题。此外,Ubuntu 18.0.4 LTS 服务器已安装在主机虚拟机上。
主机网络详细信息
ifconfig
:
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 88.44.31.30 netmask 255.255.255.255 broadcast 0.0.0.0
inet6 fe81::b62e:99fd:fecd:fd13 prefixlen 64 scopeid 0x20<link>
inet6 2a02:4f8:232:1b07::2 prefixlen 64 scopeid 0x0<global>
ether b2:2e:99:fb:3b:aa txqueuelen 1000 (Ethernet)
RX packets 2934329 bytes 1525163180 (1.5 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2799211 bytes 3794187248 (3.7 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0x51200000-51220000
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 246437 bytes 3598125972 (3.5 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 246437 bytes 3598125972 (3.5 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:53:0b:a6:6f:f0 txqueuelen 1000 (Ethernet)
RX packets 15954 bytes 1189621 (1.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 27979 bytes 283208200 (283.2 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe81::fc50:56af:fbb0:6aa4 prefixlen 64 scopeid 0x20<link>
ether fe:50:56:00:67:ab txqueuelen 1000 (Ethernet)
RX packets 870 bytes 100801 (100.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 21441 bytes 2188836 (2.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
/etc/netplan/01-netcfg.yaml
:
network:
version: 2
renderer: networkd
ethernets:
eno1:
addresses:
- 88.44.31.30/32
- 2a02:4f8:232:1b07::2/64
routes:
- on-link: true
to: 0.0.0.0/0
via: 88.44.31.1
gateway6: fe81::1
nameservers:
addresses:
- 213.133.98.98
- 213.133.99.99
- 213.133.100.100
- 2a01:4f8:0:1::abd:9912
- 2a01:4f8:0:1::abd:1022
- 2a01:4f8:0:1::abd:9844
route -n
:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 88.44.31.1 0.0.0.0 UG 0 0 0 eno1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
VM 网络详细信息
ifconfig
:
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.122.178 netmask 255.255.255.0 broadcast 192.168.122.255
inet6 fe81::fc50:bbaf:fab0:6aa5 prefixlen 64 scopeid 0x20<link>
ether 00:bb:56:aa:67:ab txqueuelen 1000 (Ethernet)
RX packets 797 bytes 302823 (302.8 KB)
RX errors 0 dropped 590 overruns 0 frame 0
TX packets 165 bytes 19312 (19.3 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 90 bytes 6966 (6.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 90 bytes 6966 (6.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
/etc/netplan/00-installer-config.yaml
:
network:
ethernets:
enp1s0:
dhcp4: true
version: 2
route -n
:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.122.1 0.0.0.0 UG 100 0 0 enp1s0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 enp1s0
192.168.122.1 0.0.0.0 255.255.255.255 UH 100 0 0 enp1s0
ISP 向我提供了以下地址:
address 88.44.31.10
netmask 255.255.255.224
gateway 88.44.31.1
因此,我需要从外部/互联网访问虚拟机,88.44.31.10
但不知道如何配置主机和虚拟机。
提前致谢。
答案1
您需要在外部接口上创建桥接。然后您可以在该桥接上为您的主机设置设备和 IP,同时还可以将您的客户机连接到该桥接上,以便在同一个面向外部的网络上工作。
这种配置的示例可以在netplan.io 示例页。
您以后可以考虑使用 OpenVswitch 作为替代方案,但这会更加复杂,因此仅在您需要它的高级功能时才有用。