【问题标题】:Puphpet/Vagrant: Unable to access LAMP VM with IP addressPuphpet/Vagrant:无法使用 IP 地址访问 LAMP VM
【发布时间】:2017-12-30 20:49:04
【问题描述】:

我使用 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 -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

我还能检查什么?

【问题讨论】:

    标签: ubuntu vagrant virtualbox ubuntu-16.04 puphpet


    【解决方案1】:

    我提供了an answer here,我认为这是相关的,但我也会将其发布在这里,以防其他人想知道这个线程以寻找解决方案。

    这听起来很像 bug in VirtualBox 5.1.24,它已在 5.1.26 中修复。

    这个问题似乎是由 VirtualBox 未能为仅主机网络创建路由引起的。要检查是否是这种情况,在您的主机上运行 vagrant up 之后,从您的终端运行 netstat -rn。这将向您显示内核 IP 路由表中的可用路由。会有几行输出,但其中你应该看到你的私有网络 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 在主页上这样说:

    官方推荐的Virtualbox版本是5.0.26!

    所以你可能想回滚到那个版本

    【讨论】:

    • 是的,我使用的是 VirtualBox 5.1.24。 netstat -rn 没有列出我的虚拟机 IP 地址。我会尝试回滚到以前的版本。
    • 我的问题已经通过回滚到以前的版本 5.0.40r115130 解决了,谢谢!我现在可以使用 ping、curl 等来访问 VM IP 地址。主机上的netstat -rn 命令有一个Iface vboxnet0Destination 192.168.56.0 的条目 - 这与我的VM IP 地址不匹配,但似乎一切正常。
    猜你喜欢
    • 1970-01-01
    • 2014-10-01
    • 2018-09-29
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    • 2018-05-09
    相关资源
    最近更新 更多