How to access Vagrant Box in public network

52,588

Solution 1

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

Solution 2

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.

Solution 3

I was unable to figure this out using anything I read (which was hours and hours of research). Instead, this is how I figured it out:

Below is my Vagrantfile. The important part for me was config.vm.network :public_network. After reloading vagrant with vagrant reload, I chose the first option of the 4 available bridged network interfaces (I’m not sure if I chose the correct one by luck, or if any would have worked, I’ll experiment), then sshed into the vagrant box with vagrant ssh, did ifconfig, chose one of the 3 ip addresses that it output, pasted that into my browser, and it worked.

The thing no one else seemed to talk about was sshing into the vagrant box and finding one of the ip addresses there. I hope maybe this helps some other networking newb in the future.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.box = "bahmni-team/bahmni"
  config.vm.box_check_update = true
  config.ssh.insert_key = false
  config.vm.network :public_network

  config.vm.synced_folder "..", "/bahmni", :owner => "vagrant"
  config.vm.provider "virtualbox" do |v|
     v.customize ["modifyvm", :id, "--memory", 4092, "--cpus", 2, "--name", "Bahmni-RPM"]
  end
end
Share:
52,588
user2439278
Author by

user2439278

Updated on July 10, 2020

Comments

  • user2439278
    user2439278 almost 4 years

    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?