VMware came with a very useful networking feature, called
host-only networking, that created a private network connection between the host and guest operating systems. This is feasible with VirtualBox, too, altough not quite as obvious. Here is described how you can do it with Ubuntu host and Windows XP guest system.
First you have to install the
uml-utilities package:
sudo apt-get install uml-utilities
Then you will have to create the virtual network interface that the two operating systems will share:
sudo tunctl -t tap0 -u giannis
Of course you will have to replace "giannis" with your own username.
Now, assign the IP 10.0.1.1 to the Host system (Linux):
sudo ifconfig tap0 10.0.1.1
We will now have to make sure that VirtualBox has full access to
/dev/net/tun:
sudo chgrp vboxusers /dev/net/tun
sudo chmod 660 /dev/net/tun
You have to add all users of VirtualBox in the
vboxusers group. You can to that either by going to
System → Administration → User and Groups, or by directly editing your
/etc/group file:
sudo gedit /etc/group
Find the
vboxusers group:
...
mysql:x:121:
vboxusers:x:1001:
postfix:x:122:
...
And add all the users that will use VirtualBox into it:
...
mysql:x:121:
vboxusers:x:1001:giannis
postfix:x:122:
...
Now start VirtualBox and before you boot your Windows XP, highlight your virtual machine and click on
Settings. Go to
Network. Find a free network adapter. Enable it and select
Attached to: Host Interface. At the
Host Interface Settings section go to
Interface Name and type in the interface's name, that is,
tap0. Click
Ok and boot your Windows XP.
When Windows is started, go to
Start → Settings → Network Connections. Find the connection you previously added and open its
Properties window. Highlight
Internet Protocol (TCP/IP) and click
Properties. Check the
Use the following IP address option. In
IP address enter
10.0.1.2. In
Subnet mask enter
255.255.255.0. Leave
Default gateway empty. It should look like this:

Click OK and then click OK once more. That's it. Now you should be able to access each from the other. To test if your private networking really works, try to ping each host from the other.
From Host (Ubuntu) use the IP 10.0.1.2 to ping the Guest (Windows XP):
giannis@giannis-laptop:~$ ping 10.0.1.2
PING 10.0.1.2 (10.0.1.2) 56(84) bytes of data.
64 bytes from 10.0.1.2: icmp_seq=1 ttl=128 time=0.455 ms
64 bytes from 10.0.1.2: icmp_seq=2 ttl=128 time=0.951 ms
64 bytes from 10.0.1.2: icmp_seq=3 ttl=128 time=0.368 ms
--- 10.0.1.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.368/0.591/0.951/0.257 ms
Note that you will have to disable firewall for that network interface in Windows XP in order for ping to work.
From Guest (Windows XP) use the IP 10.0.1.1 to ping the Host (Ubuntu):
C:Documents and SettingsGiannis>ping 10.0.1.1
Pinging 10.0.1.1 with 32 bytes of data:
Reply from 10.0.1.1: bytes=32 time=14ms TTL=64
Reply from 10.0.1.1: bytes=32 time=1ms TTL=64
Reply from 10.0.1.1: bytes=32 time<1ms TTL=64
Ping statistics for 10.0.1.1:
Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 14ms, Average = 5ms
Control-C
^C
Although all settings applied to the network interface in Windows will be available every time you boot Windows, the virtual network interface will go away next time you shut down your Linux system. One easy solution to this, is to add the commands that set up your network interface in your /etc/rc.local script:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo "Setting up tap0 interface..."
tunctl -t tap0 -u giannis
ifconfig tap0 10.0.1.1
exit 0
Now the tap0 interface will be available every time you boot your Ubuntu system. Note that you do not have to use
sudo inside
/etc/rc.local as this script is executed by
root anyway.
Update on: December 13th, 2008
Here is also a tip from Ale Feltes Quenhan: you can also have NAT working by running the following two commands:
# iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
# echo "1" > /proc/sys/net/ipv4/ip_forward
making sure to replace eth1 with the interface that gives your host machine an Internet connection.
Thanks to Ale.