为什么我无法访问我的虚拟机内的主机?

为什么我无法访问我的虚拟机内的主机?

主机:cent os 7

ip:192.168.1.3/24 默认路由:192.168.1.1

虚拟接口 ip:virbro:192.168.4.0/24 网关:192.168.4.2

知识产权在主机上

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    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: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether c0:3f:d5:66:c3:01 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.3/24 brd 192.168.1.255 scope global dynamic eno1
       valid_lft 62703sec preferred_lft 62703sec
    inet6 fe80::c23f:d5ff:fe66:c301/64 scope link 
       valid_lft forever preferred_lft forever
3: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether ac:fd:ce:03:2c:58 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.2/24 brd 192.168.1.255 scope global dynamic wlp2s0
       valid_lft 62549sec preferred_lft 62549sec
    inet6 fe80::aefd:ceff:fe03:2c58/64 scope link 
       valid_lft forever preferred_lft forever
4: ham0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1404 qdisc pfifo_fast state UNKNOWN qlen 500
    link/ether 7a:79:19:5c:7b:fd brd ff:ff:ff:ff:ff:ff
    inet 25.92.123.253/8 brd 25.255.255.255 scope global ham0
       valid_lft forever preferred_lft forever
    inet6 2620:9b::195c:7bfd/96 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::7879:19ff:fe5c:7bfd/64 scope link 
       valid_lft forever preferred_lft forever
5: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 52:54:00:35:f6:c9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.4.0/24 brd 192.168.4.255 scope global virbr0
       valid_lft forever preferred_lft forever
    inet 192.168.4.3/24 scope global secondary virbr0
       valid_lft forever preferred_lft forever
6: virbr0-nic: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
    link/ether 52:54:00:35:f6:c9 brd ff:ff:ff:ff:ff:ff

知识产权在主机上

[root@centos services]# ip r
default via 192.168.1.1 dev eno1  proto static  metric 100 
default via 192.168.1.1 dev wlp2s0  proto static  metric 600 
25.0.0.0/8 dev ham0  proto kernel  scope link  src 25.92.123.253 
192.168.1.0/24 dev eno1  proto kernel  scope link  src 192.168.1.3  metric 100 
192.168.1.0/24 dev wlp2s0  proto kernel  scope link  src 192.168.1.2  metric 600 
192.168.4.0/24 dev virbr0  proto kernel  scope link  src 192.168.4.0 

对于客户机也类似:cent os 7

ip:192.168.4.200/24 默认路由:192.168.4.2

知识产权知识产权客人 在此处输入图片描述

我也无法从虚拟机(192.168.4.200)ping 主机(192.168.1.3),提示目标主机不可达。

编辑:刚刚在虚拟机客户机中安装了 Windows,并且能够从中 ping 该客户机。

Windows 客户机:

 Link-local IPv6 Address . . . . . : fe80::7085:b96
 IPv4 Address. . . . . . . . . . . : 192.168.4.104
 Subnet Mask . . . . . . . . . . . : 255.255.255.0
 Default Gateway . . . . . . . . . : 192.168.4.0

:\Users\IEUser>ping 192.168.1.3

inging 192.168.1.3 with 32 bytes of data:
eply from 192.168.1.3: bytes=32 time<1ms TTL=64
eply from 192.168.1.3: bytes=32 time<1ms TTL=64
eply from 192.168.1.3: bytes=32 time<1ms TTL=64
eply from 192.168.1.3: bytes=32 time<1ms TTL=64

ing statistics for 192.168.1.3:
   Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

主持人 :

答案1

您必须将 IP 添加到主机的虚拟网卡。

ip a a 192.168.4.3/24 dev virbr0

然后从该 IP(192.168.4.3)上的客户机访问主机

要同时解决这两个问题,请确保已在 VM 管理程序上启用 NAT。我预计客户操作系统的默认网关是 192.168.4.1。尝试使用以下命令更改它

ip r d default via 192.168.4.2
ip r a default via 192.168.4.1

如果这不起作用,请向两个系统发送以下命令的结果:

ip a
ip r

相关内容