我使用 Puphpet.com 使用 VirtualBox 5.1.24 部署了本地 Ubuntu 16.04 LAMP 开发机器。我用虚拟机 IP 地址 (192.168.56.101) 更新了/etc/hosts。
$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 flippy
192.168.56.101 dev.mysite.com
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
我可以通过 SSH 连接到虚拟机,但无法通过 IP 地址 (192.168.56.101) 或域名访问它。
Ping 失败:
$ ping 192.168.56.101
PING 192.168.56.101 (192.168.56.101) 56(84) bytes of data.
^C
--- 192.168.56.101 ping statistics ---
164 packets transmitted, 0 received, 100% packet loss, time 166895ms
curl 失败:
$ curl -v 192.168.56.101
* Rebuilt URL to: 192.168.56.101/
* Trying 192.168.56.101...
* connect to 192.168.56.101 port 80 failed: Connection timed out
* Failed to connect to 192.168.56.101 port 80: Connection timed out
* Closing connection 0
curl: (7) Failed to connect to 192.168.56.101 port 80: Connection timed out
另外
netstat -rn
在主机上不显示 VM IP 地址的路由:$ netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 wlp1s0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 wlp1s0
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 wlp1s0
我还能检查什么?
最佳答案
我提供了an answer here我相信这是相关的,但是我也会在这里发布它,以防其他人想知道这个线程以寻找解决方案。
这听起来很像 bug in VirtualBox 5.1.24这是在 5.1.26 中修复的。
该问题似乎是由 VirtualBox 未能为仅主机网络创建路由引起的。要检查是否是这种情况,在运行 vagrant up
之后在您的主机上运行 netstat -rn
从您的终端。这将向您显示内核 IP 路由表中的可用路由。会有几行输出,但其中你应该看到你的私有(private)网络 IP 看起来像这样:
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.56.101 0.0.0.0 255.255.255.0 U 0 0 0 vboxnet3
如果您没有看到为该 IP 设置的溃败,那么您可能已被此错误所困扰。升级到 Virtualbox 5.1.26 为我解决了这个问题(在 Linux 上)。但是 puphpet.com在主页上这样说:
The official recommended Virtualbox version is 5.0.26!
所以你可能想回滚到那个版本
关于ubuntu - 傀儡/Vagrant : Unable to access LAMP VM with IP address,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45294615/