How to enable internet access inside Vagrant?

33,521

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

Share:
33,521
user2439278
Author by

user2439278

Updated on April 09, 2020

Comments

  • user2439278
    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
    user2439278 over 10 years
    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.
  • user2439278
    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
    user2439278 over 10 years
    after a long time it throws an error:curl: (7) couldn't connect to host
  • Mingyu
    Mingyu over 10 years
    You might want to check the firewall setting of your vagrant box.
  • user2439278
    user2439278 over 10 years
    could you please help me how to check it. Im new to this vagrant
  • user2439278
    user2439278 over 10 years
    Im using Ubuntu 12.04
  • Mingyu
    Mingyu over 10 years
  • user2439278
    user2439278 over 10 years
    i checked in my terminal , ufw status is disabled only. Now also facing same problem
  • user1678401
    user1678401 over 10 years
    I think user2439278 didn't run vagrant reload after adding the suggested configuration to the Vagrantfile: it solved the problem for me.
  • ke20
    ke20 about 10 years
    works fine after launch vagrant reload --provision
  • user2439278
    user2439278 about 10 years
    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 issue
  • aphexddb
    aphexddb almost 10 years
    Thank you! This fixed all my issues under Ubuntu 14.04
  • sinhix
    sinhix almost 10 years
    Perfect for me as well on Ubuntu 14.04
  • biophonc
    biophonc about 8 years
    that's exactly what I try first and most often fixes it - like: have you tried turning it off and on again?
  • Sebastiaan M
    Sebastiaan M almost 6 years
    Apparently this can also happen on a Windows (Server Core 2016) VM when my laptop sleeps and wakes up again. Thanks for the tip!