How to enable internet access inside Vagrant?
Asked Answered
A

5

38

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
Agility answered 27/8, 2013 at 5:0 Comment(0)
H
66

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
Heterophony answered 27/8, 2013 at 5:10 Comment(13)
after 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.Agility
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 endAgility
after a long time it throws an error:curl: (7) couldn't connect to hostAgility
You might want to check the firewall setting of your vagrant box.Heterophony
could you please help me how to check it. Im new to this vagrantAgility
Im using Ubuntu 12.04Agility
Checkout this link: askubuntu.com/questions/250775/…Heterophony
i checked in my terminal , ufw status is disabled only. Now also facing same problemAgility
I think user2439278 didn't run vagrant reload after adding the suggested configuration to the Vagrantfile: it solved the problem for me.Prussianism
works fine after launch vagrant reload --provisionBenevolence
it works in the machine where vagrant is running. But when i tried in another system, its not working. Please help me to fix this issueAgility
Thank you! This fixed all my issues under Ubuntu 14.04Constructive
Perfect for me as well on Ubuntu 14.04Vinegary
V
34

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.

Verleneverlie answered 3/5, 2014 at 2:46 Comment(2)
that's exactly what I try first and most often fixes it - like: have you tried turning it off and on again?Noach
Apparently this can also happen on a Windows (Server Core 2016) VM when my laptop sleeps and wakes up again. Thanks for the tip!Ghazi
P
4

Disabling firewall helped me. In my CentOS guest box I did:

# sudo service iptables save
# sudo service iptables stop
# sudo chkconfig iptables off
Pskov answered 3/10, 2014 at 15:39 Comment(0)
J
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

Justinejustinian answered 29/12, 2016 at 10:40 Comment(0)
F
0
Vagrant.configure("2") do |config|
            config.vm.define "ansible-controller" do |controller|
            controller.vm.hostname = "controller"
            controller.vm.network :public_network
      end
    end

If the curl "www.google.com" is not working the try to change the network in the vagrant file to a public_network. Then try to run curl "www.google.com". This works for me:)

Flambeau answered 4/4 at 8:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.