VirtualBox and Networking – How you do it.

Host Only with Network Routing
The Host Only networking operates just like any other network. It adds an extra network device to your computer (in Linux this is vboxnet0) and can be treated just as if it were another ethernet card.

There are two basic things you need to do in order to allow Host Only networking access to the rest of the world:

Allow traffic to flow through your computer to the virtual machines
Tell the rest of the world that the Host Only network exists
Now, I can’t tell you how to do this – the exact details are dependent on your host operating system and the other hardware on your network. Different makes & vendors have different ideas about how it should be done. I can, however, show you what to look for and how to know what you should do when you find it.

Allowing traffic through your computer
This is often known as IP Forwarding and in most operating systems is turned off by default. On most Linux systems it can be turned on by editing the file /etc/sysctl.conf and adding this line:

net.ipv4.ip_forward=1
That will set the forwarding ready for the next reboot but won’t turn it on right away. In order to do that issue this command as root:
# sysctl -w net.ipv4.ip_forward=1
In FreeBSD it’s a case of adding the following to /etc/rc.conf:
gateway_enable=”YES”
then issuing as root:
# sysctl -w net.inet.ip.forwarding=1
(note how it differs to Linux slightly)
Ok, so that’s the easy bit. Now comes the tricky part…

http://blog.superuser.com/2011/04/25/virtualbox-and-networking-how-you-do-it/