如何正确设置带有 kvm qemu 的 Linux 服务器以进行网络连接

如何正确设置带有 kvm qemu 的 Linux 服务器以进行网络连接

我有两台主机(相同的硬件),它们运行着两个不同的 Linux 发行版。两台主机都运行着 kvm-qemu,我已将 Linux 客户端的同一个 qcow 文件复制到两台主机上。我的网络使用的是地址空间 192.168.2.x,我希望客户端显示在此空间中。因此,我在 virt-manager 中的两台服务器上将接口配置为共享设备,virbr0 的类型为 virtio。对于一台服务器(名称 = virthost),行为符合预期:客户端在整个网络中可见为 192.168.2.6。对于第二台服务器(名称 = labpc1),客户端获取的地址为 192.168.122.225。我可以从服务器 labpc1 使用此地址 ping 客户端,但不能从网络中的其他主机 ping 通。因此,显然服务器配置有所不同。

[root@virthost buesser]# /sbin/ifconfig
enp5s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::2e4d:54ff:fe4e:cb79  prefixlen 64  scopeid 0x20<link>
        ether 2c:4d:54:4e:cb:79  txqueuelen 1000  (Ethernet)
        RX packets 251712  bytes 20440529 (19.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1133838  bytes 1612893332 (1.5 GiB)
        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 270  bytes 15166 (14.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 270  bytes 15166 (14.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.50  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::2e4d:54ff:fe4e:cb79  prefixlen 64  scopeid 0x20<link>
        inet6 2003:c0:370e:3600:2e4d:54ff:fe4e:cb79  prefixlen 64  scopeid 0x0<global>
        ether 2c:4d:54:4e:cb:79  txqueuelen 1000  (Ethernet)
        RX packets 234255  bytes 13306620 (12.6 MiB)
        RX errors 0  dropped 717  overruns 0  frame 0
        TX packets 230639  bytes 1504208543 (1.4 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fc54:ff:fe54:d2af  prefixlen 64  scopeid 0x20<link>
        ether fe:54:00:54:d2:af  txqueuelen 1000  (Ethernet)
        RX packets 131040  bytes 113022492 (107.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 128330  bytes 149290254 (142.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vnet1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fc54:ff:fe90:c278  prefixlen 64  scopeid 0x20<link>
        ether fe:54:00:90:c2:78  txqueuelen 1000  (Ethernet)
        RX packets 110307  bytes 145357136 (138.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 80834  bytes 60947380 (58.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vnet2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fc54:ff:fe9a:7cd  prefixlen 64  scopeid 0x20<link>
        ether fe:54:00:9a:07:cd  txqueuelen 1000  (Ethernet)
        RX packets 117  bytes 9210 (8.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1250  bytes 128326 (125.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


[root@labpc1 ~]# /sbin/ifconfig
enp5s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.8  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::29e:8b0f:c0d4:ac95  prefixlen 64  scopeid 0x20<link>
        inet6 2003:c0:370e:3600:15ca:a8a2:5173:d03c  prefixlen 64  scopeid 0x0<global>
        ether 34:97:f6:8e:c0:73  txqueuelen 1000  (Ethernet)
        RX packets 7807  bytes 830450 (810.9 KiB)
        RX errors 0  dropped 784  overruns 0  frame 0
        TX packets 5529  bytes 2526116 (2.4 MiB)
        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 12376  bytes 2419241 (2.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12376  bytes 2419241 (2.3 MiB)
        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:54:00:38:47:af  txqueuelen 1000  (Ethernet)
        RX packets 46  bytes 3516 (3.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 34  bytes 3052 (2.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fc54:ff:fe95:bcf3  prefixlen 64  scopeid 0x20<link>
        ether fe:54:00:95:bc:f3  txqueuelen 1000  (Ethernet)
        RX packets 46  bytes 4160 (4.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 279  bytes 25326 (24.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

因此在 labpc1 上,物理接口获取主机的地址,而 virbr0 获取 192.168.122.1 在 vi​​rthost 上,virbr0 具有物理主机 192.168.2.50 的(外部)地址。

有人可以解释一下吗?

非常感谢,

答案1

事实证明:默认情况下,CENTOS 8 上仅配置了 NAT。配置桥接后,它现在可以正常工作。

沃尔夫冈

相关内容