Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 
like image 576
user2439278 Avatar asked Aug 27 '13 05:08

user2439278


People also ask

How do I set up a vagrant network?

Configure port forwarding To set up a forwarded port so you can access Apache on your guest, add the config. vm.network parameter to your Vagrantfile. Below is the full file with port forwarding. Reload so that these changes can take effect.

How do I get IP from vagrant?

The IP address can be determined by using vagrant ssh to SSH into the machine and using the appropriate command line tool to find the IP, such as ifconfig .

Which interface should the network bridge to in vagrant?

Default Network Interface If more than one network interface is available on the host machine, Vagrant will ask you to choose which interface the virtual machine should bridge to. A default interface can be specified by adding a :bridge clause to the network definition.


2 Answers

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 
like image 57
Mingyu Avatar answered Sep 18 '22 19:09

Mingyu


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.

like image 25
sergiopereira Avatar answered Sep 20 '22 19:09

sergiopereira