Monday, March 8, 2010

Virtualbox: network confguration

Virtualbox comes out of the box with Ubuntu and it's really very easy to use. Why not use VMware Server (free edition)? I used to use it, but it has some disadvantages compared to Virtualbox:
- if you have a slightly non-standard linux distro, it doesn't install unless you compile the kernel modules, and this is very likely to fail (at least in my experience)
- they moved to an application server based implementation (tomcat) in version 2, which is much more resource consuming (in a computer with only 512MB RAM it is really not usable)

So, I finally switched over to VirtualBox, but one of the disadvantages of it is the networking: it's much more transparent to me in VMware than in VirtualBox. I want to be able to connect:
host (Kubuntu) <---- > guest (Solaris 10)
guest -----> outside world
world -----> guest (this is optional to me, and still not implemented, but shouldn't be too difficult)

So, based o this wiki and a few other sites/tutorials, I sum the steps I had to do to make it work:
Host:
1. enter this lines in my /etc/network/interfaces file (change user_name with the user name you're going to run VirtualBox):
iface br0 inet static
address 10.1.1.1
netmask 255.255.0.0
pre-up /usr/sbin/tunctl -t tap0 -u user_name
pre-up ip link set up dev tap0
pre-up brctl addbr br0
pre-up brctl addif br0 tap0
post-up ip route add 10.1.1.0/24 dev br0
post-up iptables -A FORWARD -i wlan0 -o br0 -j ACCEPT
post-up iptables -A FORWARD -i br0 -o wlan0 -j ACCEPT
post-up iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
post-up /bin/echo "1" > /proc/sys/net/ipv4/ip_forward
pre-down ip link set down tap0
pre-down /usr/sbin/tunctl -d tap0
post-down brctl delbr br0

2. run the command (as root) ifup br0
3. start virtualbox guest choosing from the configuration gui net -> adapter1 -> attached to: select 'bridge' -> select 'tap0', which should appear if you have configured it before

Guest:
Yeah, that really depends on which guest you're planning to run. In my case, a Solaris 10, the thing is basically (for static ip configuration):
1. enter static ip address in /etc/hosts together with a loghost entry
2. create the /etc/hostname.
3. add default router in /etc/defaultrouter
4. add the routing table (in my case, 10.1.1.0 is the bridge-tap net on the host, and 192.168.0.0 is the my real host OS subnet):
route -p add 10.1.1.0 -netmask 255.255.0.0 10.1.1.1
route add -net 192.168.0.1/16 10.1.1.1
(and maybe I'm leaving something out here....)

Enjoy