virtualbox extends my host system with several computers on the same network

21 dec 2010

to experiment with deployment i’ve installed several linux distributions using virtualbox (based on iso images). i had some problems with the networking but today i got rid of the complicated setup, used previously.

what i want

|       fedora      debian       windows    |
|    |
|          |          |          |          |
|          --------|||||||-------|          |
|                     | switch              |
                      | vboxnet0

virtualbox adds the vboxnet0 (host only network adapter) using the preferences dialog in the main gui. additionally i added masquerading, using a external script, in order to have all hosts inside the ‘host only networking’ accessing the internet. the switch is created by virtualbox automatically when selecting ‘host only networking’ using vboxnet0 per appliance.

i was using ‘=app-emulation/virtualbox-ose-3.2.10’.

how to do it

the setup is quite easy, i just wanted to write it down anyway in case it is of help for others.


in order to get each virtualbox appliance connected with the internet, masquerading is used. this is basically a one way internet connection but in my scenario there are no services provided to the outside world.

iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

dhcp server

as the virtualbox-built-in dhcp server did not work at all, i decided to use =net-misc/dhcp-3.1.2-p1 instead. so here is the configuration:

# option definitions common to all supported networks...
option domain-name "";
option domain-name-servers;

default-lease-time 600;
max-lease-time 7200;
ddns-update-style ad-hoc;

log-facility local7;

subnet netmask {
  option domain-name-servers;
  option routers;

subnet netmask {
  option domain-name-servers;
  option routers;

i run this server from a script which is also started at boot time:

dhcp eth0 vboxnet0

this is helpful as i can configure static IPs for known mac addresses. but also automatic assignment should be quite stable as all parameters can be tuned as used to.

the clients

as mentioned already, each client has to be assinged to the ’host only network’ adapter: vboxnet0. most linux distributions will try to get the host address via dhcp automatically. also each host can communicated with each other, so it is easy to do maintainance stuff.

update: 2010-12-21 modified article as it’s not clear why some things are done the way they are

article source