VirtualBox NAT Networking

VirtualBox provides 3 main network options:

  • NAT
  • host networking
  • internal network.

The built-in NAT support is very limited and impractical, host networking is only documented with respect to the bridged network setup which doesn't work with NetworkManager.

The purpose of this tutorial is to use a host networking to create a full-featured NAT environment, similar to KVM or VMWare.

Required software

We will need 2 additional packages: uml-utilites and dnsmasq. Install them with the following command:

sudo apt-get install uml-utilities dnsmasq


  1. Stop the networking
     sudo /etc/init.d/networking stop
  2. Open /etc/network/interfaces in the editor and add the following lines:
     auto vbox0
     iface vbox0 inet static
         pre-up /usr/sbin/tunctl -u USERNAME -t vbox0 >/dev/null
         up /usr/sbin/dnsmasq --interface=vbox0 --except-interface=lo \
              --bind-interfaces --user=nobody \
              --dhcp-range=vbox,,,,,8h \
              --domain=vbox.lan --pid-file=/var/run/ --conf-file
         up iptables -t nat -A POSTROUTING -o IFACE -j MASQUERADE
         down iptables -t nat -D POSTROUTING -o IFACE -j MASQUERADE
         down kill -9 `cat /var/run/` && rm /var/run/
         post-down /usr/sbin/tunctl -d vbox0 >/dev/null

    Replace USERNAME with the actual name of the user. (TODO: use groups).

    Replace IFACE with the name of the interface connected to the Internet or local network, e.g. eth0.

  3. Start the networking:
     sudo /etc/init.d/networking start
  4. Start VirtualBox application, open virtual machine settings and change the "Attached to:" option to "Host interface". In the "Interface name" field enter "vbox0".

  5. If everything is configured properly the guest will get an IP address in the range and will be fully accessible from the host without the need to define forwarding rules, just like in VMWare or KVM.

VirtualBoxNetworking (last edited 2008-09-10 11:03:15 by home)