Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Vagrant Box in public network

I had created on e box inside vagrant. In the Vagrantfile, I had given the network as

     Create a private network, which allows host-only access to the machine   # using a specific IP.   # config.vm.network :private_network, ip: "192.168.33.10"    # Create a public network, which generally matched to bridged network.   # Bridged networks make the machine appear as another physical device on   # your network.    config.vm.network :public_network 

I can't access the VagrantBox outside the VLAN. I need to access the Vagrant Box in public network. How to configure vagrantfile in such a way that I need to access in public network?

like image 558
user2439278 Avatar asked Aug 05 '13 06:08

user2439278


People also ask

How do I access vagrant from another computer?

I found how to connect to another computer locally by entering the vagrant environment, vagrant up --> vagrant ssh . And connected to another computer by typing in ssh [email protected] where 192.168. x.x is the local address to the computer.

How do I assign an IP address to vagrant?

The easiest way to use a private network is to allow the IP to be assigned via DHCP. This will automatically assign an IP address from the reserved address space. 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 .

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.

Which interface should the network bridge to 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

Uncomment the line in Vagrantfile

config.vm.network :public_network

The file will look like below

VAGRANTFILE_API_VERSION = "2"  Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|   config.vm.box = "box_name"   config.vm.network :public_network end 

Save it, restart the VM by using vagrant reload.

For VirtualBox, it'll use Bridged mode for networking. Which means the VM will acquire an IP address from the DHCP server for the VLAN.

You can also set the VLAN IP with: config.vm.network :public_network, ip: "192.168.0.160"

Refer to => Public Network

like image 124
Terry Wang Avatar answered Sep 22 '22 02:09

Terry Wang


By default, vagrant deletes the default (working) route on additional bridged networks inside the VMs. My problem which was specific for DHCP could only be solved by configuring the bridged network as follows:

config.vm.network :public_network, :bridge => 'em1',:use_dhcp_assigned_default_route => true 

Courtesy of https://groups.google.com/forum/#!msg/vagrant-up/yNhWV42pcgk/NbOck1xqtFQJ There maybe an equivalent for static IPs.

like image 30
gs_za Avatar answered Sep 22 '22 02:09

gs_za