Wednesday, May 13, 2015

Setting up a VM cluster in VirtualBox

You may come across a requirement to setup a cluster of virtual machines which need to be able to communicate among themselves as well as to access internet within each virtual machine instance. With the default network settings in VirtualBox you won't be able to achieve inter-VM communication. For that you need to setup a Host-only adapter.

Go to VirtualBox UI, File --> Preferences --> Network --> Host-only networks

Click "Add", and fill out IPV4 address as 192.168.56.1 and Network Mask 255.255.255.0. In the DHCP Server tab, untick enable DHCP server to disable it.



Now we have configured the host-only adapter. We can use this adapter when creating new virtual machines.

My requirement is to setup 2 virtual machines with the IP s 192.168.56.20 and 192.168.56.21.
I will show you how to setup one virtual machine.

Select the virtual machine you need to configure your network settings, and click on "Settings" icon --> Then click on "Network", you will get a UI as follows.


There, you tick on "Enable Network Adapter", Select Host-only Adapter in Attached to dropdown, and select the hostonly adapter that we configured earlier (vboxnet0) Click on the next tab to configure NAT, as follows.


Now you have configured both host-only and NAT Start your virtual machine.
 But still, if you do an "ifconfig" from your virtual machine you will not see any 192.168.xx ip has assigned. You need to do one more setting as follows.

Go to /etc/network/interfaces file and add following.

 #---------------------------------------
 auto lo
 iface lo inet loopback

 # Host-only interface
 auto eth0
 iface eth0 inet static
     address 192.168.56.20
     netmask 255.255.255.0
     network 192.168.56.0
     broadcast 192.168.56.255

 #-----------------------------------------

Restart your virtual machine and now you will see your 192.168.56.20 interface is up. Same way, you can configure your 192.168.56.21 virtual machine and so on....

You can ping from 192.168.56.21 machine to 192.168.56.20 and vise-versa