How to enable internet access inside Vagrant?
Solution 1
If you are using Vagrant + VirtualBox + Ubuntu, you might want to add the following block to your VagrantFile:
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
If you are using ubuntu, and you think your firewall is on
, here's how you turn off the firewall:
sudo ufw disable
Solution 2
This happens sometimes for me if I switch the host network connection, like disconnecting my laptop Ethernet cable and start using the wireless network. I found that rebooting the Vagrant vm (vagrant halt, vagrant up) fixes things.
Solution 3
Disabling firewall helped me. In my CentOS guest box I did:
# sudo service iptables save
# sudo service iptables stop
# sudo chkconfig iptables off
Solution 4
I tried all of the above without success (Vagrant+Virtualbox+Ubuntu 14.04). Virtualbox was showing 'Adapter 1 (NAT): cable disconnected'. Adding the following to my Vagrantfile fixed it:
config.vm.provider 'virtualbox' do |vb|
vb.customize ['modifyvm', :id, '--cableconnected1', 'on']
end
Found here: https://github.com/mitchellh/vagrant/issues/7648
user2439278
Updated on April 09, 2020Comments
-
user2439278 about 4 years
If I run
curl google.com
, I can't see the output, only a blank page. My Vagrantfile contains:Vagrant.configure("2") do |config| config.vm.box = "trumobi" #config.vm.box_url = "http://192.168.136.129/package.box" config.ssh.default.username = "trumobi" config.vm.network :public_network config.vm.network :forwarded_port, host: 8000, guest: 8000 end
-
user2439278 over 10 yearsafter adding the above comments in my vagrantfile, im facing the same prob. When i give curl www.google.com, i cant able to view the ouput. Only blank screen is been displayed. Please find below the updated vagrantfile.
-
user2439278 over 10 years
Vagrant.configure("2") do |config|
config.vm.box = "trumobi"
#config.vm.box_url = "http://192.168.136.129/package.box"
config.ssh.default.username = "trumobi"
config.vm.network :public_network
config.vm.network :forwarded_port, host: 8000, guest: 8000
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
end
-
user2439278 over 10 yearsafter a long time it throws an error:curl: (7) couldn't connect to host
-
Mingyu over 10 yearsYou might want to check the firewall setting of your vagrant box.
-
user2439278 over 10 yearscould you please help me how to check it. Im new to this vagrant
-
user2439278 over 10 yearsIm using Ubuntu 12.04
-
Mingyu over 10 yearsCheckout this link: askubuntu.com/questions/250775/…
-
user2439278 over 10 yearsi checked in my terminal , ufw status is disabled only. Now also facing same problem
-
user1678401 over 10 yearsI think user2439278 didn't run
vagrant reload
after adding the suggested configuration to the Vagrantfile: it solved the problem for me. -
ke20 about 10 yearsworks fine after launch
vagrant reload --provision
-
user2439278 about 10 yearsit works in the machine where vagrant is running. But when i tried in another system, its not working. Please help me to fix this issue
-
aphexddb almost 10 yearsThank you! This fixed all my issues under Ubuntu 14.04
-
sinhix almost 10 yearsPerfect for me as well on Ubuntu 14.04
-
biophonc about 8 yearsthat's exactly what I try first and most often fixes it - like: have you tried turning it off and on again?
-
Sebastiaan M almost 6 yearsApparently this can also happen on a Windows (Server Core 2016) VM when my laptop sleeps and wakes up again. Thanks for the tip!