How can I access a VirtualBox host-only network from outside the host machine?

4

1

I'm using Vagrant to deploy a large virtual network environment for testing out some applications and network activity. I'm using host-only networking so I can define all the IP addresses in my Vagrantfile, but one of the applications I'm required to use for testing is an external appliance that cannot run as a virtual machine.

So, I'm wondering if it's possible to route traffic incoming to the host machine destined for the host-only LAN. I know this goes against the idea of host-only networking, but I cannot use bridged networking in this case because Vagrant isn't able to set static IP addresses on bridged guest interfaces.

I've tried the following:

  1. Added route on appliance telling it to use external IP address of VirtualBox host as the gateway for any traffic destined for the host-only LAN.
  2. Turned on IP forwarding on VirtualBox host
  3. Added route on VirtualBox host to forward any traffic destined for the host-only LAN to the vboxnet0 interface.
  4. Tried pinging one of the VirtualBox guests on the host-only LAN from the external appliance -- no success.

Any ideas if this is at all possible?

EDIT:

It might be worth noting that I can ping the IP address of the host-only interface on the VirtualBox host (interface vboxnet0) from the external appliance.

Bryan

Posted 2012-12-02T18:39:02.720

Reputation: 513

dumb i know, but you've made sure the virtual guest has no firewall in place ? – Sirex – 2012-12-02T18:47:08.360

Step 3 looks wrong to me. You want to set the default gateway to be the vboxnet0 interface, not just the stuff for the host-only lan. – Sirex – 2012-12-02T18:48:30.857

@Sirex - yes sir, I have made sure the virtual gues has its firewall turned off. I can ping the virtual guest from the host, but not from the external appliance. As for step 3, if I set the VirtualBox host's default gateway to be the host-only LAN, then it will not be able to get out to any other network... – Bryan – 2012-12-02T18:49:03.150

@Sirex - your second comment just opened my eyes to something... I needed to add a route to the virtual guest in order for it to be able to route response packets to the external LAN my appliance is on. Once I did that, I was able to communicate. :-) – Bryan – 2012-12-02T18:53:19.973

Even with a default gateway on the guest of the host-only adaptor on the host it should be able to, because ip-forwarding is enabled on the host. Whatever works though :-) – Sirex – 2012-12-02T19:13:25.160

Answers

1

Turns out I forgot a step... I needed to add a route to the virtual guest telling it how to get to the external LAN my appliance is sitting on via the IP address of the vboxnet0 interface on the VirtualBox host. Once I did this, I was able to communicate with it externally.

thanks @Sirex for commenting on my question enough to make me think about it more!

Bryan

Posted 2012-12-02T18:39:02.720

Reputation: 513

1Could we see an example on how you did it exactly ? I think I understand but cannot figure it out myself. – Dolanor – 2014-08-10T21:50:03.240

Feel free to accept your own answer. (Question found after Community bumped it to the front page. That is a bot who does that a few times per day for unsolved questions). – Hennes – 2013-09-10T21:54:36.930