无法从stream动虚拟机发出出站HTTP请求

我无法从我设置的Vagrant虚拟机内连接到互联网。

例如,在根,当我input:

curl http://google.com 

它失败的消息:

 curl: (6) Couldn't resolve host 'google.com' 

我不确定是否是防火墙设置,但据我所知,我还没有为端口80或任何其他端口创build任何防火墙规则。

这是我的stream浪文件的相关部分。 如果有任何其他信息可以提供,请在评论中告诉我们:

 Vagrant.configure("2") do |config| # All Vagrant configuration is done here. The most common configuration # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com. # Let Vagrant manage the hostname at boot config.vm.hostname = "devbox" # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. # config.vm.network :forwarded_port, guest: 80, host: 8080 # Create a private network, which allows host-only access to the machine # using a specific IP. config.vm.network :private_network, ip: "10.0.0.10" # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network :public_network # Create a public network with a given hardware address. You can # configure your DHCP server (on your router) to assign a particular IP # address to the VM. Update your hosts file accordingly. # config.vm.network :public_network, mac: "0a00251010101" # Share an additional folder to the guest VM. The first argument is # the path on the host to the actual folder. The second argument is # the path on the guest to mount the folder. And the optional third # argument is a set of non-required options. #config.vm.synced_folder "vagrant/logs", "/logs", # owner: "root", group: "root" # Base box to use with Virtualbox provider config.vm.box = "debian-7.0.0-amd64-base" config.vm.box_url = "http:/mysite.com/debian-7.0.0-amd64-base.box" 

Solutions Collecting From Web of "无法从stream动虚拟机发出出站HTTP请求"

这看起来像一个DNS配置问题。 做一个nslookup google.com ,看看结果是什么。

尝试在您的Vagrantfile添加以下块,将Vagrantfile设置为on,以强制VirtualBox NAT引擎拦截DNS请求并将其转发给主机的解析器

 config.vm.provider :virtualbox do |vb| vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] end 

顺便说一句:没有vagrant reload ,你可以直接查看虚拟机内的/etc/resolv.conf ,可以手动将其设置到您的网络的DNS服务器,很可能它会正常工作。