I have a remote server (ubuntu) with 1 public IP.

I've installed headless VirtualBox and deployed machine. For now I can access it by VirtualBox's VRDE Server running on server, but what i need is to be able to access virtual machine directly ... so how can i configure networking ? AFAIK Virtual Box doesn't allow to access it's NAT from outside, so it leaves me with bridge option, but I have only one external IP available . What are my options?

  • Is getting another IP possible?
    – tombull89
    Jul 12 '13 at 9:32
  • Why don't you have IPv6? Jul 12 '13 at 9:34
  • Tom : I think I can get another IP, but what then ?
    – Kubber
    Jul 12 '13 at 10:11
  • Michael : how Ipv6 could help me ?
    – Kubber
    Jul 12 '13 at 10:11
  • @ShlafRock you have one external ip for the host, and one for the guest...what is it you actually want to do?
    – tombull89
    Jul 12 '13 at 14:44

Use hostonly networking. You add an interface to your network configuration for your virtualbox that acts like a switch. By default it should add vboxnet0.

On your machine you need to enable ip4 forwarding in the kernel:

sysctl -w net.ipv4.ip_forward=1

This should be enough to allow internet access for the VM. You can filter the traffic using iptables and the FORWARD chain if you add an interface for each VM you can even filter by interface and restrict traffic between VMs. It's the most flexible way to do it. And you can avoid bridging.

Using iptables you can forward a port to the local vm:

iptables -t nat -A PREROUTING -i eth+ -p tcp --dport 2222 -j DNAT --to

Where is the ip address of your VM on the interface vboxnet0 that can be reached from outside via port 2222. You can either configure the IP by hand or use dnsmasq on the host to act as an DHCP server.

Put a file in /etc/dnsmasq.d/virtualbox for your VM:


This takes care of assigning the IP-address and gateway + DNS information to the VM. You can configure it also by hand in this case DNS and gateway address would be If you are familiar with linux network configuration you should be able to figure this out.


If you configure a "host-only" interface, VirtualBox will use a virtual interface on the host. You can define forwarding to that interface.

To use a host-only interface, start VirtualBox, and from the "File" menu choose "Preferences". Choose "Network" in the window which appear, and press the "add" button. After adding the network, press the "settings" button on the right. There, you can edit the virtual network settings. The "IP Address" will be the host's IP address on that virtual network.

Make sure the DHCP server option is switched off.

If you're done, press the "OK" button. After this, you can select "host-only" in the network preferences of the guest computer. It will default the interface to the one you created in the above steps.

Start the virtual machine. Give it a fixed IP address, and set up the gateway. You should be able to ping the guest computer's IP address from the host and vice versa.

A new adapter will appear on the host operating system, named "vboxnet0". Through this, the guest computer will be reachable, but only from the host computer (of course). You can configure port forwarding on the host computer as usual, and with this, you can access your guest directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.