Here I am documenting how to create TAP interfaces and using them in VirtualBox in OS X. I think in Linux the procedure is somewhat easier. My system is Mac OS X 10.5.6; that shouldn´t matter much.
- We will be using the command line as superuser (root); that can be dangerous if you aren´t careful. You have been warned.
- I am assuming that you already have a VM prepared to be run to which you want to add host-only networking. It must be shut down (not only paused); let´s hope that VirtualBox will get the capability of changing VM network options while running (like VMware does).
- If you are lucky, the procedure is not complicated. If you aren´t, you might need some networking knowledge to fix whatever small problem appears (arp... routing?). Anyway, normal networking in the Mac should not be affected.
- Download and install the TUN/TAP drivers. You can do so from http://tuntaposx.sourceforge.net or with MacPorts.
- Prepare the TAP interface by typing this on a terminal window:
Code: Select all
sudo bash # we go superuser exec 4<>/dev/tap0 # opens device, creates interface tap0 ifconfig tap0 10.10.10.1 10.10.10.255 ifconfig tap0 up hexdump -c <&4 # reads from device - a cheap etherdump (Here, the tap0 interface is working, try ping 10.10.10.255 and see the packets appear... When you don´t want the TAP interface any longer, press control-C and continue) exec 4>&- # closes device, destroys interface tap0
- Now we want to set one of the VM´s network interfaces to Host Interface mode, and set it to be bridged against our new TAP interface. BUT, that can´t be done in the GUI; I'm assuming that that is a bug in v2.1.4 at least, since we can do so without any problem from the command line. That´s what we are going to do.
Code: Select all
VBoxManage list vms # shows your VMs; get the name of the one to be modified (here, "MyVM") VBoxManage modifyvm MyVM -nic3 hostif # set interface 3 to Host Interface mode VBoxManage modifyvm MyVM -hostifdev3 tap0: # and bridge it to our TAP
- Start the VM and configure the new network interface. In this example, the TAP interface in the Mac has been configured to use address 10.10.10.1; the VM could use address 10.10.10.2, for example. You will have to use manual configuration, since there is no DHCP server.
- With a bit of luck, you could already be done! Try pinging the Mac from the VM, and viceversa. For completeness, you could also try ssh'ing one from the other, or accesing some other service.
- If things still don´t work, shutting down the VM and VirtualBox and starting them again could help. You can try also closing the TAP interface and opening it again.
But, if still something is wrong, in my setup I found a couple of strange problems that you could check for. The Mac had got a wrong ARP resolution for 10.10.10.2 (the VM´s IP); with arp -a I saw that both 10.10.10.1 and .2 were resolved as the MAC in the TAP interface. That can be easily solved with arp -d 10.10.10.2 (to force a new resolution), or even force the correct value with arp -s 10.10.10.2 AA:BB:CC:DD:EE:FF (with AA:BB:CC:DD:EE:FF being the MAC address of the 10.10.10.2 interface in the VM; you can get it with ifconfig if the guest is Linux or in the network properties in Windows).
Another tip: a quick way to check that the virtual network is working is by using some Bonjour application. For example, "Bonjour Browser" in OS X will show services published by the VM (avahi/zeroconf in Linux). BUT, even if Bonjour is working, normal networking can still be failing because of arp issues!
Regards.