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 cant able to 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?
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 withvagrant 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), thenssh
ed into the vagrant box withvagrant ssh
, didifconfig
, 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
ssh
ing into the vagrant box and finding one of the ip addresses there. I hope maybe this helps some other networking newb in the future.Uncomment the line in
Vagrantfile
config.vm.network :public_network
The file will look like below
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
Single VM environment
you can use command:
vagrant ssh
Multi VM environment
you can use command:
vagrant ssh {hostname}
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:
Courtesy of https://groups.google.com/forum/#!msg/vagrant-up/yNhWV42pcgk/NbOck1xqtFQJ There maybe an equivalent for static IPs.
Finally! This is years later but I couldn't find more current info. For me, the problem was that I not only had a private network defined, but also a forwarded port, and all that was working well. I then commented out the private_network, replaced it with public_network, and couldn't reach anything. Tried everything I found here and elsewhere, no go. It's only when I commented out the port forwarding that things started working again, without any of the manual bridging/dhcp configuration rigamarole suggested.