Search code examples
vagrantvirtualbox

How can I access a vagrant guest from another virtualbox guest?


The scenario is that my dev environment is on a Vagrant box on my laptop (host) and I would like to do browser testing in a vitualbox vm, so I need to see one vm from another.

The vagrant box's port is :8080 which is forwarded to the host on the same port :8080. So I can see the server from the host at localhost:8080

Which address should I be using for the browser testing vm?

The testing vm's default gateway? The vagrant vm's ip? The host's virtual network ip?

And should I be using a NAT or host only adapter on the browser testing vm?

That makes for a lot of combinations, all of which I believe I have tried. What else do I need to understand here?


Solution

  • In your use case, you should be using Bridged networking (Public Network in Vagrant). If the VMs reside on the same host, you can even use internal (Private Network in Vagrant).

    If using Public Network, the VM's 2nd NIC will be able to obtain an IP address from the DHCP server in your network (e.g. your home router).

    Simply add the following code block in your Vagrantfile and do a vagrant reload

    Vagrant.configure("2") do |config|
      config.vm.network "public_network"
    end
    

    You should be able to get the IP address by using vagrant ssh and ifconfig / ip addr show.