user2439278
user2439278

Reputation: 1214

How to enable internet access inside Vagrant?

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

Upvotes: 38

Views: 39009

Answers (5)

Tharindu
Tharindu

Reputation: 1

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:)

Upvotes: 0

4Oh4
4Oh4

Reputation: 2161

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

Upvotes: 4

vgrinko
vgrinko

Reputation: 198

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

# sudo service iptables save
# sudo service iptables stop
# sudo chkconfig iptables off

Upvotes: 4

sergiopereira
sergiopereira

Reputation: 2056

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.

Upvotes: 34

Mingyu
Mingyu

Reputation: 33359

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

Upvotes: 66

Related Questions