查找 NAT 后面的虚拟机公共 IP 地址

查找 NAT 后面的虚拟机公共 IP 地址

我有 NAT。
我的公网 IP 地址是79.30.22.215
我的 NAT 范围是192.168.1.x/24
我的客户机 IP 地址是192.168.1.3

所以这是我不明白的:如果我ipconfig从我的Windows主机运行,它会说我的虚拟机网卡有192.168.56.1一个 IP 地址 - 即出去我的 NAT 范围。

Scheda Ethernet VirtualBox Host-Only Network:
Suffisso DNS specifico per connessione:
Indirizzo IPv6 locale rispetto al collegamento . : fe80::421:3d14:c4ce:8fe2%23
Indirizzo IPv4. . . . . . . . . . . . : 192.168.56.1
Subnet mask . . . . . . . . . . . . . : 255.255.255.0
Gateway predefinito . . . . . . . . . :

但是当我ifconfig从我的虚拟机运行时:

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:feb1:29e6  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:b1:29:e6  txqueuelen 1000  (Ethernet)
        RX packets 141  bytes 61843 (60.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 252  bytes 33249 (32.4 KiB)
        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 1  (Local Loopback)
        RX packets 214  bytes 17108 (16.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 214  bytes 17108 (16.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

所以我的问题是:如果我必须从远程主机连接到我的虚拟机,我应该使用什么 IP 地址?

答案1

解决了 :
因此现在我按照@Paul的建议,将我的 VM 网络设置从 更改为NAT interfacebridged interfaceifconfig从 VM 运行我获得以下内容:

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.2  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a00:27ff:feb1:29e6  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:b1:29:e6  txqueuelen 1000  (Ethernet)
        RX packets 15  bytes 2602 (2.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 180  bytes 28135 (27.4 KiB)
        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 1  (Local Loopback)
        RX packets 167  bytes 14439 (14.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 167  bytes 14439 (14.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

现在一切正常。谢谢。

相关内容