Linux – How to connect to virtualbox’s host-only network from outside using openvpn

linuxopenvpnvirtualboxvirtualization

What i want to do is:

  • have an internal network for guest systems / be able to make connections between guests inside network
  • have internet connection for guests (to download updates)
  • be able to connect to guests with ssh(linux guests)/rdp(windows guests)

My Setup is: Ubuntu oneiric host system using Virtualbox for Virtualizing some guests (linux & windows).

I setup two network adapters for each guest:

  • NAT
  • Host-only-networking vboxnet0

I'm trying to setup a openvpn server on the host system to allow connections to the host-only network vmnet0. Giving a public ip address to the guests is not an option for me, as i do not want to have this guests be public accessible and also i do not have enough ip addresses to provide to the guests.

I installed openvpn server and tried both bridging into the vboxnet0, which simply had no connectivity at all, as also using routed ip tunnel:

dev tun
server 192.168.56.0 255.255.255.0

with the last config i'm able to connect to the vpn server and get an internal ip address. I'm able to ping the server at 192.168.56.1 but can not ping to the guest (192.168.56.101). If i make the ping from the main server, i can ping to both addresses.

I'm not experienced with iptables, so i did not setup any rules for this, which MAY be the problem. I have tried enabling ipforwarding on the host system (sysctl -w net.ipv4.ip_forward=1), but it did not have any effect.

So my questions are:

  1. Should the openvpn setup work out of the box, or is it needed to setup some forward rules in iptables?
  2. If yes, how would the rules look like?
  3. And simply: what should i do to make it work?

Best Answer

Firstly, is there a reason that VirtualBox's port forwarding on NAT interfaces isn't sufficient? You could setup various ports on the host to forward to SSH and RDP ports on the VMs.

I suspect that VirtualBox doesn't allow external access to the host only network. You could try running another VM to act as the VPN server. It would also have both a NAT and host-only NICs, with a port forward on the NAT interface to accept incoming VPN traffic.