gpt4 book ai didi

php - 无法从 vagrant VM 发出出站 HTTP 请求

转载 作者:IT王子 更新时间:2023-10-29 00:05:34 28 4
gpt4 key购买 nike

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

例如,在根目录下,当我键入:

curl http://google.com

失败并显示消息:

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

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

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

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"

最佳答案

这看起来像是 DNS 配置问题。执行 nslookup google.com 并查看结果。

尝试在你的 Vagrantfile 中添加以下 block ,将 --natdnshostresolver1 设置为 on 以强制 VirtualBox NAT 引擎拦截 DNS 请求并将它们转发到主机的解析器

config.vm.provider :virtualbox do |vb|

vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]

end

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

关于php - 无法从 vagrant VM 发出出站 HTTP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22901859/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com