Wednesday, February 25, 2009

configuring host interface networking for virtualbox on ubuntu

Host interface networking is a network option in virtualbox that allows your VM to share the host network card. With this option the VM can have its own routeable IP address on your network. It is unfortunate that this setup is not as simple as choosing this option and clicking OK.

To use host interface networking for your virtualbox VM, you must first create a bridge to your physical network interface.

Follow these steps to create a bridge:

1. install bridge-utils, uml-utilities package
% sudo apt-get install bridge-utils uml-utilities

2. put your NIC (e.g. eth0) in promiscuous mode
% sudo ifconfig eth0 0.0.0.0 promisc

3. create the bridge br0
% sudo brctl addbr br0

4. attach bridge (e.g. br0) to NIC (e.g. eth0)
% sudo brctl addif br0 eth0

5. configure IP address for your bridge (e.g. br0)
% sudo ifconfig br0 192.168.1.2
or if you're using dhcp
% sudo dhclient br0

6. skip this step if you're using dhcp. configure the default gateway (e.g. 192.168.1.1) for your bridge (e.g. br0)
% sudo route add default gw 192.168.1.1 br0

7. create virtual NIC (e.g. veth0)
% sudo tunctl -t veth0 -u root

8. attach the bridge (e.g. br0) to your virtual NIC (veth0)
% sudo brctl addif br0 veth0

That's it! Now your VM can use veth0 as its network interface. In the settings|network settings of your VM, choose "Host Interface" in the Attached to drop down box. Then use veth0 as the host interface name. If your network has a DHCP server, it should be broadcasting DHCP request to veth0 otherwise you will have to configure the network manually on your VM.

No comments: