Search This Blog

There was an error in this gadget

Friday, April 18, 2008

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):


ipconfig-output-there-is-a-new-ip-in-the-lan-now


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:

ping-vm1-and-vm2-from-a-vm

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.

40 comments:

  1. 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 !!!

    ReplyDelete
  2. I don't understand why have you created two adapters in virtual machines (eth0 and eth1)?

    ReplyDelete
  3. Great Post- I had struggled with getting a XP guest OS working in my Vista box. Looked at the VirtualBox documentation and no help. I saw the promiscuous notes, but hadn't found what that meant yet or how to set it in Vista. I am pretty sure you have saved me many hours of searching. More importantly, you saved my computer from a sledgehammer.

    ReplyDelete
  4. THANK YOU!! This was the information I needed to finally get my Ubuntu guest visible on the network. XP Host, Ubuntu guest, so slightly different configuration, but the bit about how to configure the adapter and bridge was exactly what I'd been missing. WOO HOO!!!

    ReplyDelete
  5. Telling users to disable UAC is not responsible. UAC increases security of Windows.

    ReplyDelete
  6. Hi Gaurav,
    I spent a full day to find the way to bridge a wireless connection with my Virtual Box adapter! Thank you so much!!

    ReplyDelete
  7. Thanks for the posting. Worked like a charm.
    - Pete

    ReplyDelete
  8. Nice article - thanks for the tips.

    Being a newbie to VM's, this is usually indeed, and you have presented your article in a very clear fashion.

    ReplyDelete
  9. Dun, you may be required to open the ports in VM (centos) and allow the firewall in XP.

    ReplyDelete
  10. how to make it realized on linux???
    in my case:

    #host:
    debian

    #guest:
    ubuntu.1
    ubuntu.2
    ubuntu.3
    ubuntu.4

    ReplyDelete
  11. [...] una solución por internet, pero no me resolvió el problema. No analizé mucho el porqué ni como debia solucionarlo, pero en [...]

    ReplyDelete
  12. [...] Virtualbox Case Study: Making host only networking work between two Ubuntu Guest OS (virtual machin... [...]

    ReplyDelete
  13. Hi,

    great instruction. I although have a new poblem when I do this solution.

    HOST = Vista
    Guest = Ubuntu 9.04

    when apply the solution, i receive the IP address thru the DHCP and can see the router. Can also interact with all -behind router - devices. BUT can not browes the internet or after router network!!

    Indeed it could be a router problem, but my host has no issues going to internet and after router network!!!

    Please help.

    thanks

    R

    ReplyDelete
  14. He's running two virtual machines. One adapter is bridged to the host's physical network adapter to access the outside world. The other adapter is bridged to the second VM's virtual adapter, so the two VM's can communicate directly.

    ReplyDelete
  15. Fantastic, started using Sun VB today. Zero experience with this, but your consise tut got it working for me in mere seconds. You rock!

    ReplyDelete
  16. What is the Virtualbox Network Adapter configuration for gsm mobile edge network.I am using Aircel (iNDIA) but failed to connect internet in Virtualbox machine ubuntu 9.04. Please help.

    ReplyDelete
  17. Sorry, Ty. I dont know the answer to this one, but i think you can tamper with the /etc/sysconfig/network files for changing the MAC address of the network interface and see if that works.

    ReplyDelete
  18. Hi,

    I have the same question as Mario had. I am using Ubuntu 9.04 and I can't see such two options. How can we create this two type of interfaces? I just got VIirtualbox 1 on both VMs.

    Can you inform how to create two interface?

    Thanks.

    ReplyDelete
  19. If you are talking about creating bonding, then it would need to be done through command line. Kindly google and you will find really good examples. Im a little short of time with my current projects right now. Sorry. If you do find a good link, please post a comment and I will approve them. Thanks much and sorry.

    ReplyDelete
  20. Actually I am not sure, host networking is useful for me or not. What I want to do is explained here. Any help is appreciated.

    [1] I have two separate host machines.
    [2] On each machines I have multiple Ethernet connection. [using USB to Ethernet converter]
    [3] Now I want to install guest OS in such a way that it can have only single Ethernet connection to it. So if I install 3 guest os on host machine, they 3 have different Ethernet connection and they should not talk to each other.
    [4] I am running routing software Quagga [on Ubuntu guest os] and it should connect to the other guest machines installed on other host machine over the network.

    So basically, I want to assign separate Ethernet interface to separate guest OS.

    So can you help me in this?
    Which networking type [host-only, bridged or NAT] I should use? I have to give static ip address to each guest os Ethernet interface.

    Thank you.

    ReplyDelete
  21. Thank you so much. It works now !!!!

    ReplyDelete
  22. Have you looked into private networking article on this blog website?

    ReplyDelete
  23. Hi,

    I am able to do this using bridged networking. I just assign different interface to different guest and separate static ip address for each interface. I am able to perform routing by this way.

    Thanks everyone for help.

    ReplyDelete
  24. Hello Sir,

    I did exactly the steps you mentioned.
    I have Vista host and SUSe 11.2 in VirtualBox.

    After bridging I got an ip 192.168.56.104 and I assigned IP of 192.168.56.10 to SUSE 11.2

    It pings both the ways from Vista to SUSE and vice-versa.

    But the problem is putty client cannot connect from Vista to VirtualBox. It says "Connection Timed out". What may be the problem?

    Also I have disabled firewall in Vista

    Please Help Me

    ReplyDelete
  25. Sorry I figured it out. It was problem with SUSE firewall. I added Secure SHELL server to firewall and putty client started working like charm. Thanks for such great article

    Regards
    Nanda

    ReplyDelete
  26. I tried to setup the vbox by following the sample but could not make it work. Host is vista and guest is Suse. Wireless router. First issue is after bridge and enable the both api, the internet connction lost. I have to use cable connection to get on internet from host side.
    The other issue is ping from guest side is still "destination host unreachable".
    Host static IP address 192.168.0.101. Gateway 192.168.0.1, DNS is 4.2.2.2. Gateway and DNS is fixed by wireless router. I do not how to control with IP address of Vbox (Host) on vistal side but it will not be same as IP address on Suse side. I have set up static address on suse side and setup forwarding to Host IP address and default gateway as same as 192.168.0.1. It might to do the bridge ipaddress? Could any tell what should I do to fix that kind issue.

    Thanks.

    ReplyDelete
  27. This article is quite a bit out-of date. This was written around the time VirtualBox 1.6 came out. VirtualBox 2.1 introduced a driver interface for host systems. With 3.1.6, you now have "Host-Only" and "Bridged." For what this article is trying to accomplish, Bridged is what you want.

    ReplyDelete
  28. Hello,

    I have installed virtual box in my HP laptop and i lost my wireless internet connection as well as LAN also, is anyone one can help me out,

    Help will be appreciated

    Thanks
    Yogesh

    ReplyDelete
  29. Wondering how to put an 192.168.2.2 /24 to an interface, point its gateway to 192.168.0.1 and you did it work

    ReplyDelete
  30. I guess you don't realize it, but all that effort you went to is effectively the same as just using 'bridged' networking in VirtualBox rather than setting up a bunch of host and virtual adapters then bridging them.

    Theres no need for any of this, just use bridged in the first place and you accomplish the exact same thing.

    ReplyDelete
  31. we like Centos, this Good OS system

    ReplyDelete
  32. Can anyone tell me how to connect virtual machines in vmware workstation using network.

    My query is:

    On vmware workstation i made two virtual machines of redhat linux and install oracle 11g both on them.

    Now i want to work on both virtual machines as Server and Client.

    My question is how i can connect to server from client, there should be a connection to a server with the help of network in between two machines.

    If anyone having the idea how to do it please let me know with step by step how to configure it.

    the purpose to do this is: On server there will be a listener.ora file who listens the request from a client with the help of tnsnames.ora.

    I want know how to make connection in both of this on linux operating system. please reply me if anyone nows

    Please let me know on my email address: aijaz5k@yahoo.com

    best regards,

    ReplyDelete
  33. I am using virtual box.
    Host OS: Vista SP1 and Guest OS : WinXP SP2

    I have installed some application server in both and want to connect/call the application from host to guest and vice versa. Like giving a request URL(http:///application from guest and vice versa) in browser by mentioning

    ReplyDelete
  34. The article is good to understand for novice user

    ReplyDelete
  35. hi, i m using oracle applications on red hat linux guest and the host is windows XP , the host only network option is working properly , as i am able to ping the both guest and host,
    and they are able to talk to each other, but the problem arises, when i try to open the oracle applications from windows host, the first page is opened in the internet explorer browser and then the connection is lost...?????/

    Any answer to this will be highly appreciated

    virat2687@yahoo.co.in

    ReplyDelete
  36. Thanks for the tutorial and this saved lot of time!

    ReplyDelete
  37. thanks a lot, i follow your instructions, do not know where i turn wrong, but afterwards ( neither know how ) it comes to work :-D so again thanks for your guidence

    ReplyDelete