39

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
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
user2439278
  • 1,222
  • 7
  • 41
  • 75

4 Answers4

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
Mingyu
  • 31,751
  • 14
  • 55
  • 60
  • 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 Aug 27 '13 at 05:17
  • 1
    `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 Aug 27 '13 at 05:18
  • after a long time it throws an error:curl: (7) couldn't connect to host – user2439278 Aug 27 '13 at 05:22
  • You might want to check the firewall setting of your vagrant box. – Mingyu Aug 27 '13 at 05:27
  • could you please help me how to check it. Im new to this vagrant – user2439278 Aug 27 '13 at 05:30
  • Im using Ubuntu 12.04 – user2439278 Aug 27 '13 at 05:30
  • Checkout this link: http://askubuntu.com/questions/250775/how-do-i-turn-off-the-firewall-in-ubuntu-12-04 – Mingyu Aug 27 '13 at 05:34
  • i checked in my terminal , ufw status is disabled only. Now also facing same problem – user2439278 Aug 27 '13 at 05:42
  • I think user2439278 didn't run `vagrant reload` after adding the suggested configuration to the Vagrantfile: it solved the problem for me. – Confusion Dec 09 '13 at 21:37
  • works fine after launch `vagrant reload --provision` – ke20 Feb 13 '14 at 09:57
  • 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 – user2439278 Feb 21 '14 at 10:23
  • 1
    Thank you! This fixed all my issues under Ubuntu 14.04 – aphexddb Jun 02 '14 at 17:45
  • 1
    Perfect for me as well on Ubuntu 14.04 – sinhix Jul 07 '14 at 03:20
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.

sergiopereira
  • 2,026
  • 2
  • 23
  • 31
  • 2
    that's exactly what I try first and most often fixes it - like: have you tried turning it off and on again? – biophonc Feb 15 '16 at 20:48
  • Apparently this can also happen on a Windows (Server Core 2016) VM when my laptop sleeps and wakes up again. Thanks for the tip! – Sebastiaan M Jun 19 '18 at 17:15
4

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

# sudo service iptables save
# sudo service iptables stop
# sudo chkconfig iptables off
vgrinko
  • 198
  • 1
  • 1
  • 9
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

4Oh4
  • 2,031
  • 1
  • 18
  • 33