I’m creating a new development server on VirtualBox. I was using VMWare until recently, but since upgrading to Ubuntu 9.04 64bit, I’ve decided to try VirtualBox instead. I also recommended VirtualBox to my brother, so by using it myself I’ll be better able to support him if he has any issues.
Installing a new virtual machine was a breeze. After I activated hardware virtualisation in my bios, I installed a 64bit version of Ubuntu server 8.04 LTS. The install failed a couple of times, not sure why, but third time lucky.
My first major stumblingĀ block was connecting to the virtual machine from the host machine. By default VirtualBox gives the guest (virtual machine) a NAT ethernet connection. So the guest can connect to the network, including the internet, but the host can’t connect to the guest. I’m creating a development server, so that’s precisely what I want to do, connect from the host to the guest. With a little reserach, it turns out there’s an easy solution (on Linux hosts).
The VirtualBox article on Advanced Networking in Linux was my guide. I’ll document all the steps I took here.
Install bridge-utils, vtun and uml-utilities:
sudo apt-get install bridge-utils vtun uml-utilities
Create the bridge:
sudo brctl addbr br0
sudo ip link set up dev br0
sudo ip addr add 10.9.0.1/24 dev br0
Create a tap device for the guest to use, put your username in place of USER:
sudo tunctl -t tap0 -u USER
sudo ip link set up dev tap0
sudo brctl addif br0 tap0
If you need multiple guests connected, repeat this step replacing tap0 with tap1, tap2 and so on. Always use br0.
Now modify the virtual machine settings and map one of the network adapters (probably the second one) to the device tap0. Choose Attached To Host Interface and select the device tap0. I left the first network adapter as a NAT adapter so the virtual machine has internet access. In this configuration, I can disconnect the guest from the internet and / or the host separately.
When the virtual machine has started, setup the network. Assuming the guest is an Ubuntu machine, run these commands on the guest. If you linked the first network adapter to tap0 then use eth0 on the guest, if you chose the second network adapter use eth1, 3 to eth2, 4 to eth3 andĀ so on.
sudo ip link set up dev eth1
sudo ip addr add 10.9.0.2/24 dev eth1
Now test it all works. On the host machine try ping -c4 10.9.0.2 and on the guest try ping -c4 10.9.0.1. Assuming both machines are set to respond to pings (default in Ubuntu), you should see 4 successful pings.
If this works, you can set the address permanently by editing /etc/network/interfaces and adding this text.
# Host only network
iface eth1 inet static
address 10.9.0.2
netmask 255.255.255.0
network 10.9.0.0
broadcast 10.9.0.255
I’ve used the 10.9.*.* addresses as an example. You can use any private network address (10.*.*.*, 192.168.*.* or 172.16.*.*-172.31.*.*). The most commonly used addresses are 192.168.*.* and 10.0.*.* or 10.1.*.* so I recommend staying away from them. You want to choose addresses that won’t clash with anything else on your network.

Hello Sensei… I’m not sure when, but I will try Ubuntu soon. I found OSCAR which is an opensource hospital information solution and runs on Ubuntu.
See you soon in my Linux and opensource adventures
Wonderful news sensei. If you need any Ubuntu or linux related help, my lines are always open for you my friend.
Good Job, thanks
exactly what I’m looking for… I’ll try it later… thx very much
Amazingly easy instructions, thx a bunch!!!!
Thanks Callum!
Your guide was concise and worked perfectly. You described how to make the changes persistent by defining the interface in the guest’s interfaces file in /etc/network. I did that and when I rebooted my guest OS, eth1 was not present when I did an ifconfig. I then did ifconfig eth1 up, but it did not have an ip address defined. I am running ubuntu server 9.10 as the guest and ubuntu desktop 9.10 as the host. I verified that my /etc/network/interfaces addition was the same as what you posted, but the changes still do not persist between GUEST restarts. (I attached eth1 to tap0 like you suggested)
I can create a script to do…
Also, is there a need to change any config on the host to make the creation of the bridge and the tap persistent?
Thanks again for the great guide.
Kevin
It’s been a while since I set this up myself. I honestly can’t remember if or how I automated the brctl and tunctl stuff. I probably stuck it in a script somewhere, I’m not sure. You could look into running scripts automatically on startup and then put it in a script, I think that’ll work, but I’m not sure. Best of luck with it. Feel free to post back here if you find a way to get it working.
I finally got virtualbox up and running again, but I’m still running 8.04 as the guest. The changes are persistent and last across sessions. Here’s what I have in /etc/network/interfaces:
# Host only networkauto eth1
iface eth1 inet static
address 10.9.0.2
netmask 255.255.255.0
network 10.9.0.0
broadcast 10.9.0.255
Do have the auto eth1 part? I realise I missed that from my howto. Or did you find a solution already?
I have not gotten it working already. I am still using the exact steps from your guide, but I put them into scripts that I execute prior to launching the VirtualBox software. It works perfectly, but I’ll try what you posted here, when I get home, and let you know how I fare with it.
Thanks for the follow-up
I recently updated to Ubutnu 10.04 becausae of it’s LTS, but since that time VBox does not start when I setup the bridge network. I have to disable eth1 to boot virtual system…
I took a screenshot of the error message
http://files.tomasjancik.net/Screenshot.png
I tried to modprobe the modules, but still it didnt work…
can you help?
Apologies for the delayed reply, your message slipped into oblivion in my inbox. I recently set up Virtualbox on 10.04 and it works ok for me. As I read your error message, it seems like your tap0 interface doesn’t exist. Check the virtual machine settings, maybe you have network adapters mapped to the machine which no longer exist?
Callum
Thanks for your contribution. I have a slight problem which is also replicated on the virtualbox documentation; on which machine do I type the above commands- ie the guest or the host? Please help.
I’m not sure which commands you’re asking about. The first part is on the host, the second the on the guest. The last two code blocks are on the guest, everything else is on the host.
You can also simply use the “Bridged Adapter” instead of or in addition to the default NAT adapter.
The guest should then be able to fetch an IP from the hosts network and you can talk to the guest using that IP.
Worked easey peasey for me (Winblows host, Ubuntu10 guest)
That approach only works if you have a live network connection on the host. I have a development server on my laptop so I like to be able to work whether or not I have a wifi or ethernet connection. Also, as I switch connections, I’d have to change the bridged settings depending on which network card I’m using. It is a simpler option when the host has a continuous network connection.