Virtualbox Case Study: Making host only networking work between two Ubuntu Guest OS (virtual machine) on Windows Vista host
Preface
In the past articles, I have talked about how to make internal networking work between two virtual machines built using Virtualbox. In this article, we will see seeing a configuration of host only networking between two virtual machines built on virtualbox.
The advantages of configuring host only networking are :
1) Internet works (yes!)
2) You get an IP on the LAN for each virtual machine. Yes, this is really possible. So this means that you can have 2 more real LAN IPs coming out of a single windows desktop/laptop in the LAN. Isn’t that amazing?
3) Due to 2), your host machine can also ping or access your virtual machine
4) Each virtual machine can access the other virtual machine. E.g. ping/ssh/telnet into it.
For most purposes, this kind of setup should be optimal or sufficient. Hey, if you can access your machines in the LAN and internet works from them, that should be good enough. And, its for free.
Here is a bird’s eye overview of the end setup..
click here to enlarge this diagram
The Virtualbox Network Adapter configuration
We start with the Virtualbox Network Adapter configuration. We create a host only network interface on each virtual machine definition.
For Virtual machine1 - Gutsy:
For Virtual machine2 - gutsy2:
Please note here that while this article primarily deals with setting up host only networking, in the previous article, I had setup internal networking too, so these VMs also have a Virtual Host Interface 2 for internal networking within themselves.
Install the Guest Operating system on the virtual machines
Now, do the installation of the guest operating system in the virtual machine and setup the two network interfaces like this.
Note here that I chose static IP 192.168.0.5 because my windows machine (host OS) had the IP 192.168.0.3 and the IP had to be in the 192.168.0.x subnet. My windows host was behind a Netgear router.
We need to make sure we choose non-conflicting IPs for the host only interface otherwise you will get an IP conflict in your LAN domain. For the other machine, the eth0 static IP was 192.168.0.4.
An interesting fact here was that if I chose DHCP for eth0 in the VM, i was getting an IP of 192.168.0.3, the same as that of my windows host!! This is another reason why I had to choose static IP address.
For eth1, i chose a random IP in the subnet 192.168.2.x for no particular reason. The eth1 IP of the other virtual machine was 192.168.2.1
Make sure to restart the network after doing this network setup to bring it into effect.
Do not bother about the SIOCADDRT: No such process error:
gverma@gverma-laptop:~$ sudo /etc/init.d/networking restart [sudo] password for gverma: * Reconfiguring network interfaces... SIOCADDRT: No such process Failed to bring up eth1. [ OK ]
For the benefit of the reader, the DNS and host information is also reproduced here, although the only thing of significance should be the DNS and default gateway, both of which were set to be the same as that on windows host:
This is how the network configuration on the other virtual machine looked like:
For those who are interested, here is the output of the route command:
gverma@gverma-laptop:~$ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.2.0 * 255.255.255.0 U 0 0 0 eth1 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 link-local * 255.255.0.0 U 1000 0 0 eth0 default 192.168.0.1 0.0.0.0 UG 100 0 0 eth0
A quick side note for Windows Vista
Here is a quick side note for Vista or windows in general. It is preferable to disable the UAC (user access control) setting and also disable the firewall on the host windows machine.
Disable the User Access Control (UAC) feature on vista to make your life easier:
Network bridging: the key to make host only networking work
The KEY to make host only networking work on windows is to bridge the real working network interface (either wireless connection of a hard wired ethernet) with the virtual adapter network interface. You can do this by selecting two network interfaces, right click, choose bridge and voila, there you have it.
A network bridge is nothing but a simplified concept of joining two connections into one. Its like joining two rivers into a bigger river. When water will flow into the bigger river, it will flow into both the rivers. At least, this is how I understand it.
ALSO, we have to enable promiscuous packet routing mode in ALL the member network interfaces that are in the bridge. This is an important setup to make it work.
Initially, I had struggled a lot to make host only networking work by enabling promiscuous for only the Virtualbox Adapter in the bridge, but was not successful. That is when I read a cryptic posting on the Virtualbox forum saying that it has to be done for all the member bridge interfaces; and thats when it worked.
A note of caution
When we add an adapter to the bridge, the connection of the main wireless network is lost for a moment, but it is re-enabled back. This is also covered in the user manual in secion 6.3 (Virtualbox version 1.5.6)
Warning: Setting up Host Interface Networking requires changes to your
host’s network configuration, which will cause the host to lose its network
connection. Do not change network settings on remote or production systems
unless you know what you are doing.
Later on, I assigned Virtualbox Host Interface 2 (on windows) to NAT0 (eth0) of Virtual machine 2 and bridged it to the wireless network connection too:
After the bridging, this is how the ipconfig output looked like (the IP of the windows host is 192.168.0.3):
Now, we were one BIG, HAPPY Family. Make sure the connection status shows as connected.
Testing the connections - Internet works!
At this point, the internet was working from the virtual machines:
Another real quick check is to use the wget utility:
gverma@gverma-laptop:~$ wget yahoo.com --18:32:56-- http://yahoo.com/ => `index.html' Resolving yahoo.com... 216.109.112.135, 66.94.234.13 Connecting to yahoo.com|216.109.112.135|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: http://www.yahoo.com/ [following] --18:32:57-- http://www.yahoo.com/ => `index.html' Resolving www.yahoo.com... 69.147.114.210 Connecting to www.yahoo.com|69.147.114.210|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 9,490 (9.3K) [text/html] 100%[=====================================================>] 9,490 --.--K/s 18:32:57 (258.06 KB/s) - `index.html' saved [9490/9490]
Testing the connections - Host only networking
Now comes the acid test of whether the virtual machines and hosts can see each other.
Windows could see the individual virtual machines:
C:\Users\gaurav> ping 192.168.0.4 Pinging 192.168.0.4 with 32 bytes of data: Reply from 192.168.0.4: bytes=32 time<1ms TTL=64 Reply from 192.168.0.4: bytes=32 time<1ms TTL=64 Reply from 192.168.0.4: bytes=32 time<1ms TTL=64 Reply from 192.168.0.4: bytes=32 time<1ms TTL=64 Ping statistics for 192.168.0.4: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms C:\Users\gaurav> ping 192.168.0.5 Pinging 192.168.0.5 with 32 bytes of data: Reply from 192.168.0.5: bytes=32 time<1ms TTL=128 Reply from 192.168.0.5: bytes=32 time<1ms TTL=128 Reply from 192.168.0.5: bytes=32 time<1ms TTL=128 Reply from 192.168.0.5: bytes=32 time<1ms TTL=128 Ping statistics for 192.168.0.5: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms
Pinging the windows host IP from inside the VMs worked beautifully:
And, pinging to the other virtual machine from each VM worked beautifully too:
Taking this a step further, since ssh was enabled on both the virtual machines, I was able to login to the individual virtual machines also:
gverma@gverma-laptop:~$ ps -ef | grep ssh gverma 4684 4643 0 21:27 ? 00:00:00 /usr/bin/ssh-agent x-session-manager root 5422 1 0 22:20 ? 00:00:00 /usr/sbin/sshd gverma 5456 4864 0 22:23 pts/0 00:00:00 grep ssh gverma@gverma-desktop:~$ ssh 192.168.0.5 gverma@192.168.0.5's password: Linux gverma-desktop 2.6.22-14-generic #1 SMP Sun Oct 14 23:05:12 GMT 2007 i686 The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Mon Apr 14 22:20:55 2008 from gverma-laptop.local gverma@gverma-desktop:~$
gverma@gverma-desktop:~$ ssh 192.168.0.4 The authenticity of host '192.168.0.4 (192.168.0.4)' can't be established. RSA key fingerprint is a8:29:91:97:7d:99:37:6e:31:f1:06:ec:04:39:78:d7. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.0.4' (RSA) to the list of known hosts.
gverma@192.168.0.4's password: Linux gverma-laptop 2.6.22-14-generic #1 SMP Sun Oct 14 23:05:12 GMT 2007 i686
The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
Private networks
To make things better, the private networks were working too (thanks to the good karma accumulated in the previous article - Case study: Configuring Internal networking work for talking two linux guest OS (Ubuntu) on windows vista host ) :
gverma@gverma-laptop:~$ ping 192.168.2.1 PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data. 64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.200 ms 64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=1.16 ms 64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=0.000 ms 64 bytes from 192.168.2.1: icmp_seq=4 ttl=64 time=0.073 ms --- 192.168.2.1 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3006ms rtt min/avg/max/mdev = 0.000/0.358/1.160/0.468 ms gverma@gverma-laptop:~$ ping 192.168.2.2 PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data. 64 bytes from 192.168.2.2: icmp_seq=1 ttl=64 time=4.49 ms 64 bytes from 192.168.2.2: icmp_seq=2 ttl=64 time=0.368 ms 64 bytes from 192.168.2.2: icmp_seq=3 ttl=64 time=1.65 ms 64 bytes from 192.168.2.2: icmp_seq=4 ttl=64 time=3.15 ms 64 bytes from 192.168.2.2: icmp_seq=5 ttl=64 time=1.51 ms
A moment of Triumph
So here we are. Let us take a moment to sit back, relax and let reality sink it. It is really working! I am reminded of the umpteen times I had gone to forums.virtualbox.org to find the answer to this riddle and here it is, solved.
I hope this guide is of use to someone else who is trying to make a similar configuration work or just trying to understand — what is it that we can achieve from host only networking??
Nothing could be sweeter, nothing.
Filed under: Virtualbox, Virtualization, host only networking, internal networking, windows host | Tagged: host only, networking, Ubuntu, virtual machine, Virtualbox, windows host


















Hey Gaurav,
I liked the way you have presented your ideas pictorially . Looking at the pictures and your documentation, one can easily understand the topic.
Keep Blogging !!!
[...] Eine sehr gute Anleitung findet sich hier. [...]
Hi Gaurav,
What a great case study, your step by step instruction make me understand very well how to setup network under virtualbox. The most clearest virtualbox network setup explaination which I found from google.
Thank you!
Hello Nurasto, Thanks a LOT for your kind words. I was just like many other wannabe opensource experimenter who wanted to get this good looking piece of software work, but faced many silly issues. To make it easier for the next person, i thought it would make sense to jot these ideas down. I am very thankful that virtualbox.org people linked these articles on their howto page and hence allowed more people to look/evaluate the ideas. Wishing you good luck — regards, Gaurav
Hi Gaurav,
May be you know how setting up Host Interface Networking based on TCP/IP routing.
Best regards
Arik
I don’t understand why have you created two adapters in virtual machines (eth0 and eth1)?
Hey Gaurav
Thanks man for all your contribution for making it work. I am following your case studies to use virtual box on my setups. Gaurav I am facing one big problem.
I want to set up host only interface when we add an adapter to the bridge then my network on host system gets lost. And it do not come up. It says network cable unplugged. I am using windows XP as host system and ubuntu8.04 as guest. Can you help me in resolving this issue?
Thanks in advance.
Hi gaurav…………………
Xcellent !!!!!!!!!!!!!!!!!!!!. it worked. thanks a lot !!!!!!!!!!!. I was looking for such a solution. Thanks and keep up the good work !!!!!!!!!!!!!!