I am unable to connect to the internet from within a Vagrant virtual machine I have set up.
For example, at the root, when I type:
curl http://google.com
It fails with the message:
curl: (6) Couldn't resolve host 'google.com'
I'm not sure if it's a firewall setting, although as far as I know I have not created any firewall rules for port 80 or any other port.
Here is the relevant section of my Vagrantfile. If there is any other information I can provide please let me know in the comments:
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"
Simply CMD-SHIFT-P then "Remote-SSH: Connect to Host..." and the ssh . config entry you just added is automatically listed - you simply select it and voila, vscode connects to your remote vagrant vm!
This will allow accessing port 80 on the guest via port 8080 on the host.
Default Network InterfaceIf more than one network interface is available on the host machine, Vagrant will ask you to choose which interface the virtual machine should bridge to. A default interface can be specified by adding a :bridge clause to the network definition.
This looks like a DNS configuration issue. Do a nslookup google.com
and see what the result is.
Try to add the following block in your Vagrantfile
, set --natdnshostresolver1
to on so as to force the VirtualBox NAT engine to intercept DNS requests and forward them to host's resolver
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
BTW: Without vagrant reload
, you can directly look into the /etc/resolv.conf
inside the VM, can manually set it to the DNS server of your network, most likely it'll work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With