Thursday, April 9, 2009

Creating Host Only network adapter with virtual box on OS X

Here is a step by step on how to create a Host Only Virtual network adapater for Virtualbox in the same sense that host only network adapters work with vmware fusion or parallels. This method uses a tap virtual network adapter on the host os to allow the host os AND the virtual machine to communicate without ever having to send an ethernet frame out onto a wire (or into the air) everything happens within the host os.

Start by downloading the Tun/Tap software from the sourceforge page here: http://tuntaposx.sourceforge.net/

Next add the following to a bash script and give it execute permissions (Taken from this post on the vbox forrums: http://forums.virtualbox.org/viewtopic.php?f=8&t=14871&p=66322#p66322)

echo "starting"
exec 4<>/dev/tap0
ifconfig tap0 10.10.10.1 10.10.10.255
ifconfig tap0 up
ping -c1 10.10.10.1
echo "ending"
export PS1="tap interface>"
dd of=/dev/null <&4 & # continuously reads from buffer and dumps to null

sudo run the script.

Next modify your vbox guest os via the command line like so:

VBoxManage modifyvm "MyVM" -nic2 hostif #make the second network adapter host-networking
VBoxManage modifyvm "MyVM" -hostifdev2 tap0: # connect that adapter to tap0: (make sure to include the : colon after the tap0)

Start the guest machine.

Configure the guest machine (depending on your distro) to activate the eth1 device with a static ip address in the 10.10.10.255 range with the netmask of 255.255.255.0

Now from the hostos try and ping the guest os on the ip address you gave eth1 above.

If all goes well it should respond to the ping (firewall permitting of course)

If you feel like it go ahead and modify the /etc/hosts file on your host os to point a human readable name like "virtualbox" at the ip address you configured for eth1 on the guest os.

No comments: