Thursday, April 09, 2009

Creating Tap interface on Windows to allow for communication with Virtualbox guest os

OpenVPN *a project that I have always loved since its early days (I created a very reliable vpn for 10 users on different os's with an old pentium 90 as the host machine back in 2003 on it) Happens to come with a tun/tap driver for windows 2000 and XP as far as I know... possibly even Vista. Using this tun/tap driver you can actually create tap devices for your own purposes (not just for OpenVPN use) and if your thinking what I am typing you can create a setup much like in my last post where your virtual box guest os uses the tap interface for it's host only network adapter and thus you don't need any host to guest (and vice versa) network communication to leave the host machine. IE you don't need the host machine to be connected to any actual network for the two os's to talk to each other.

I have torn the following step by step instructions from here (http://milksnot.com/joomla/index.php?option=com_content&view=article&id=29&Itemid=25)

Download and install OpenVPN for Windows.
After installation of OpenVPN, a so-called TAP interface should already be installed.
Now rename the existing TAP interface to 'OpenVPN'. We won't otherwise touch this adapter, because we might want to use it with OpenVPN. If you won't be using OpenVPN, then you can skip the part below were you install a second TAP adapter. You do however need to do the configuration bit.
You can add a TAP interface in two ways: Either use the installed script at "start/program files/openvpn/Add a new TAP-Win32 virtual ethernet adapter" or do it manually. If you prefer the latter, then you do not even have to install OpenVPN. You can extract the driver from the installation package and use only that. If you prefer a manual install, this is how you would go about it:

Open Control Panel and select Add Hardware
Select 'Yes, I have already connected the hardware'
Select 'Add a new hardware device'
Select 'Manually select'
Select 'Network adapters'
Select 'Have disk'
Browse to 'C:\Program Files\OpenVPN\driver' and select 'OemWin2k.inf'
Select 'TAP-Win32 Adapter'
Some messages may appear about driver signing. Ignore them.
You do not need to reboot in order to use the new interfaces. Removing a device can be done in Computer Management/Device Manager/Right-click-on-device/uninstall. Now configure the new TAP interface.

Open the Network Connections window and look for the new adapter. It will be called something like 'Local Area Connection'.
Rename the adapter to 'TAP'
Open TAP's properties and browse to General/Adapter/Advanced
Set the adapter's Media Status to 'Always Connected'. If we skip this, then the host machine won't be active on the TAP's network.
Now configure the IP address and mask of the TAP adapter. NOTE: Use a range not in use by any of your other adapters. I spent bloody two hours trying to discover why my networks were not networking only to discover I forgot to disable two VMware network interfaces which were using the same range as I was using with the TAP interfaces.
Using the adapter in VirtualBox: When configuring an interface on a virtual machine, select 'Attached to: Host Interface' and the select the adapter called 'TAP-Win32 adapter V8 #2' from the list of adapters. And from here on it's business as usual.

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.