Search This Blog

There was an error in this gadget

Sunday, April 13, 2008

Case study: Making Internal networking for talking between two linux guest OS (Ubuntu) on windows vista host

Preface


For the past few days, I had been struggling with making internal networking work on two (or more) linux guest OSes on Windows host using virtualbox.

The advantage of this setup is we can setup an internal networking lab between two or more nods using regular windows, which can be used for a variety of purposes. My primary purpose behind this setup was to simulate an environment for implementing Oracle 10gR2 RAC cluster.

As we know, setting up 10g RAC on a node needs a public network and a private network. The public network is achieved right off the bat with the NAT network configuration in Virtualbox, but the internal network setup is one that is pretty tricky.
I will give credit to both http://www.virtualbox.org/wiki/Testing_Networks and http://blogs.sun.com/manoj/entry/netowkring_with_virtualbox for the ideas tested, but more so to http://www.virtualbox.org/wiki/Testing_Networks

That being said, I would daresay that the content authoring in Virtualbox user manual about setting up internal networking on windows host deserves a little more attention. I was able to find several posts on the internet, including a particular Virtualbox wiki page, that dealt with making host only networking or internal networking work on Ubuntu host, but was not able to find the same for windows host.

Lets get to the setup now..


This is how the GUI setup looks like internal network (Adapter 1 - 2nd adapter) for the two virtual machines:




The caveat...


The first thing which we need to understand that is the Virtualbox GUI for setting up internal network is BROKEN!

You need to set it up using the command line interface (VboxManage command) Also, be aware that the internal network settings are reset by the GUI if any of the VM settings are changed, so you better do this AFTER you are done with all the other VM changes.

As per the User manual, the default internal network name is "intnet", but you can choose any other name. I chose the intnet for no particular reason.

This is what we need to do with the VboxManage command. (here, we assume that there are two guest OSes - "Gutsy" and "gutsy2"). Mind you, the virtual machine name is case-sensitive in the VboxManage command.

c:\Program Files\Innotek> VboxManage modifyvm Gutsy -nic2 intnet

c:\Program Files\Innotek> VboxManage modifyvm Gutsy -intnet2 intnet

c:\Program Files\Innotek> VboxManage modifyvm gutsy2 -nic2 intnet

c:\Program Files\Innotek> VboxManage modifyvm gutsy2 -intnet2 intnet


Default Gateway and DNS of eth1 interfaces - (used for private network as per our semantics)


If you already have the eth0 in the guest OS (linux) as NAT, it will automatically acquire a DHCP assigned IP in the subnet 10.0.2.x, and will have a default gateway of 10.0.2.2. The names server will be 10.0.2.3. With this setup, internet will work on the linux guest OS, (provided it is works on the windows host too).



We will need to make the default gateway of the private network (eth1) in guest OS (linux) as 10.0.2.2 too -- whichever is causing the internet to work.

Private IPs should be the same subnet...


Another thing to notice here is that all the guest OSes that are intended to be connected through internal network should have the private interface IP (eth1) in the SAME subnet. You can choose any private subnet like 192.168.x.x or 10.10.x.x:

Here are three valid combinations of eth1 IPs:

a) Gutsy could have 192.168.2.1, and gutsy2 could have 192.168.2.2


b) Gutsy could have 192.168.3.2, and gutsy2 could have 192.168.3.4


c) Gutsy could have 10.10.1.1, and gutsy2 could have 10.10.1.2



( I hope you get the idea).

For the sake of illustration, I chose this combination of private IPs:

  • 192.168.2.1 (for linux guest OS 1 - Gutsy)

  • 192.168.2.2 (for linux guest OS 1 - gutsy2)




Restart networking


After doing this, you need to restart the networking on the linux host. On Ubuntu, it is done with the sudo /etc/init.d/networking restart command:
gverma@gverma-desktop:~$ sudo /etc/init.d/networking restart
[sudo] password for gverma: ********
* Reconfiguring network interfaces...
SIOCADDRT: No such process
Failed to bring up eth1.
[ OK ]

Overview of the networking configuration


Here is how the ifconfig for Gutsy - linux guest OS 1 looks like (as you can see the eth0 IP has been acquired in 10.0.2.x subnet by the DHCP server):



And this is how it looks of Gutsy2 (as you can see, the eth0 IP has been acquired in 10.0.2.x subnet by the DHCP server):
By mistake, I have put the same image for the ifconfig output (that of Gutsy) for Gutsy2  as well. The hardware MAC address for eth1/0 should be different and so should be the the IP address for eth1 -- it should be 192.168.2.1. The eth0 IP for Gutsy2 would still be 10.0.2.x as it was of NAT type. -- Thanks, Gaurav



A variation...


Let us consider a variation here.

If the Virtual machines have only 1 virtualbox network adapter defined of type internal network, then the internal static IP within the Virtual machine would have needed to use a default gateway == host's IP default gateway.

For example, if the windows host had an IP of 192.168.0.4 (say), by virtue of being behind a router, then the default gateway of eth0 interface in in the virtual machine should be 192.168.0.1. (Again, this is assuming ONLY if you do not have a NAT type virtual interface defined for the VM.)



In my case, since I had two virtual network interfaces defined (one NAT and one internal networking type) for the VMs, I had to make the default gateway of the eth1 (private interface) of guest OS the same as that of eth0 -- which was 10.0.2.2.

The default gateway can be verified by the output of route command.


Interesting Trivia


In addition, the media state of the Virtual TAP Adapters in windows host were showing up as media disconnected, but still the internet was working for the Virtual machines AND the pings to each other were working. So, don't be fooled by the status of Virtulbox Adapters in the windows host.

gverma@gverma-desktop:~$ ping 192.168.2.1
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=0.031 ms
64 bytes from 192.168.2.2: icmp_seq=2 ttl=64 time=0.030 ms
64 bytes from 192.168.2.2: icmp_seq=3 ttl=64 time=0.109 ms
64 bytes from 192.168.2.2: icmp_seq=4 ttl=64 time=0.031 ms
64 bytes from 192.168.2.2: icmp_seq=5 ttl=64 time=0.036 ms
64 bytes from 192.168.2.2: icmp_seq=6 ttl=64 time=0.033 ms
64 bytes from 192.168.2.2: icmp_seq=7 ttl=64 time=0.110 ms

--- 192.168.2.2 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 5998ms
rtt min/avg/max/mdev = 0.030/0.054/0.110/0.035 ms

gverma@gverma-desktop:~$ ping 192.168.2.2
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.398 ms
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.304 ms
64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=0.380 ms
64 bytes from 192.168.2.1: icmp_seq=4 ttl=64 time=7.20 ms
64 bytes from 192.168.2.1: icmp_seq=5 ttl=64 time=0.407 ms
64 bytes from 192.168.2.1: icmp_seq=6 ttl=64 time=0.272 ms
64 bytes from 192.168.2.1: icmp_seq=7 ttl=64 time=3.42 ms
64 bytes from 192.168.2.1: icmp_seq=8 ttl=64 time=0.411 ms
64 bytes from 192.168.2.1: icmp_seq=9 ttl=64 time=0.398 ms

--- 192.168.2.1 ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 8004ms
rtt min/avg/max/mdev = 0.272/1.465/7.200/2.241 ms

Viola! The same result can be seen on gutsy2 too.

Well done!


Congratulations on setting up a private internal network between multiple virtual machines using Virtualbox. I hope this tutorial is of use to someone exploring the virtualbox tool. I personally feel it is a lot leaner and powerful, as compared to the vmware's size. It is also more robust performance wise.

If you feel this was helpful, send me a note at gaurav_verma two two [at] yahoo dot com or just leave me a comment.

14 comments:

  1. Rajesh, make sure you setup the network interface in ubuntu as DHCP. Also make sure the name server is the same as that on your windows host (take it from the ethernet or wireless connection)

    ReplyDelete
  2. My set up is :
    Windows XP SP3 host,
    Sun xVM VirtualBox 1.6,
    Ubuntu 8.04 guest,
    Xubuntu 8.04 guest.

    I followed your tutorial to the letter and everything worked like you said it would. This was a very good tutorial. Thanks a ton, man! Great work :)

    ReplyDelete
  3. Al, you are right. By mistake, I have put the same image for the ifconfig output (that of Gutsy) for Gutsy2 as well. The hardware MAC address for eth1/0 should be different and so should be the the IP address for eth1 -- it should be 192.168.2.1. The eth0 IP for Gutsy2 would still be 10.0.2.x as it was of NAT type. -- Thanks, Gaurav

    ReplyDelete
  4. hello!
    thank you very much for this great tutorial!
    i am using it on my project @ OS Admin: samba, nfs, nbd comparisson!
    I have win xp as host.. with Virtual Box two Debian guests. This was exactly what i was looking for. The host only networking looks nice too, but i get my IP from dhcp (student campus) and I would have LAN confflict.
    all works well now, and the two guests are visible by IP.
    indeed, spared me for some hours of searching forums.
    all the best! kiri from Romania

    ReplyDelete
  5. Thanks for these great case studies! They were very helpful! Needed to set up a windows server 2003 guest host as the "main server" for a game design company which would act a domain controller and having windows xp pro connect to it and other domain controllers, all very confusing, seeing as I have ubuntu in virtual box already a simple "ping" between the VM's was used proove i understand classful IP addressing and all manner of things! :-)
    Just wanted to say thanks from Terry in England!

    ReplyDelete
  6. Thanks for the help man.
    I appreciate it.

    ReplyDelete
  7. I have seen the same behaviour and this seems to be some sort of a bug. The workaround seems to be to do the reverse ping first and then try the ping you want to do. It seems to work that way. Good luck.

    ReplyDelete
  8. This post was great ! Awesome ! Thanks for gathering and sharing these info

    ReplyDelete
  9. You have just save my time..I have been using VMware and wanted to try out VB. I had same issues where guest os can't communicate bwt each other. Your tutorial is great and easy to follow. Now my XP guest can talk to my Ubuntu Server guest.

    Thank you so much, this is awesome...!

    ReplyDelete
  10. Hi, thanks for your post! I have the same problem about the ping as for dany84. Furthermore ssh from host to guest is not working either but http requests are working!
    I wonder why.
    host: Windows Vista
    guest: ubuntu server with LAMP

    ReplyDelete
  11. let the truth be told, i have been trying to do this for 6months!!!!!!!!!!
    thanks man!!

    ReplyDelete
  12. Hi!

    Wonderful post! I need some help. I'm completely new to Linux. I'm trying to set
    up the following scenario:


    +-----+eth0 +-----+ +---+
    | VM2 |-----------| VM1 |---------------| H |
    +-----+ eth1 +-----+eth0 (NAT) +---+


    VM2 - Virtual machine from Virtual Box, using Ubuntu
    VM1 - Virtual machine from Virtual Box, using Ubuntu: I want this to act as a NAT.
    H - Host, my Windows Vista

    So if I ping H from VM2, H would receive a different IP address from VM2. Could you give me a step by step on this? Not sure what networking notes to use.

    Thanks. Would appreciate the help so much.
    --

    ReplyDelete
  13. For each nodes of the rac, how many network cards need to have?

    ReplyDelete
  14. This is a really good post
    Following all steps, my configuration looks equal and table route is the same, so pinging to the internet works fine, ping from the guest to host works, and also pinging to the route, but guest to guest fails.

    Any idea?
    Thanks.
    Regards

    ReplyDelete