如何从客户机本身找到我的 VirtualBox 客户机的主机 IP 地址?

如何从客户机本身找到我的 VirtualBox 客户机的主机 IP 地址?

有没有办法发现哪个是 VirtualBox VM 的主机?
我的 VM 来宾专用网络是“桥接适配器”(无 NAT)。
示例ifconfig如下:

CODE: SELECT ALL   EXPAND VIEW
enp0s9: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.36  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::f821:6317:c27a:16c6  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:f6:b5:54  txqueuelen 1000  (Ethernet)
        RX packets 6889970  bytes 9898198227 (9.2 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 587306  bytes 43842901 (41.8 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 1002  bytes 105104 (102.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1002  bytes 105104 (102.6 KiB)
        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:73:34:0f  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

示例netstat -rn输出:

CODE: SELECT ALL   EXPAND VIEW
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.99    0.0.0.0         UG        0 0          0 enp0s9
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 enp0s9
192.168.122.0   0.0.0.0         255.255.255.0   U         0 0          0 virbr0

主机和客户机都是 Linux CentOS 7。

答案1

一个解决方案是定义一个仅主机网络

在 VirtualBox GUI 中,选择file -> Host Network Manager
这将创建一个名为主机网络管理器
如果屏幕主机网络管理器为空,点击创造

添加仅主机网络

主机的 IP 将是192.168.56.1,即仅主机网络

$ ifconfig | egrep ':|inet'
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.101  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::a30b:4c65:13a6:ab5a  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:99:af:b0  txqueuelen 1000  (Ethernet)
enp0s9: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.196  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::b7d:99d3:7106:46e9  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:da:3c:5b  txqueuelen 1000  (Ethernet)
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>
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:73:34:0f  txqueuelen 1000  (Ethernet)

相关内容