Update: keep the CPU settings to one CPU and RAM usage to below 4GB to avoid issues with the virtual network cards. And make sure you comment the bind-address line in your my.cnf for inter-network database interaction.
For some reason it was surprisingly hard to find correct info on how to setup several virtual machines accessible through SSH with static ips. Note that my goal was to have each VM be able to connect to the internet as well as being accessible as if on the same LAN as the host machine.
Being able to access the VMs from “the outside” so to speak was not a priority.
The basic crux here is to understand that choosing different adapter types will result in different ethX numbers.
The below step by step works for Ubuntu 12.04 host running several Ubuntu 12.04 64bit Server guests in VirtualBox 4.2.14.
The below is based on this great Mac version which you probably want to check out instead if you’re running VirtualBox on a Mac host. It’s even got screen shots!
1.) Go to File -> Preferences -> Network -> Add Host Network (the plus button to the right). Then click the screw driver, also on the right, to edit. Go to the DHCP Server tab and turn it off, note the Adapter ip address which should be 192.168.56.1. This network showed up as vboxnet0 for me.
2.) Do the whole Add/Install procedure to actually setup your guest. The steps to to this are outside of the scope of this tutorial since it’s pretty straightforward and I/people rarely have problems with that.
3.) After the install the networking probably won’t work but eventually you end up being logged in. Change your /etc/network/interfaces file to look like this:
iface lo inet loopback
iface eth2 inet dhcp
iface eth3 inet static
Note the address IP, don’t put 1 at the end there, it’s the IP of the host! Shutdown the machine.
4.) Select your new machine in the machine list in VirtualBox and click Settings -> Network. In the Adapter 1 tab you enable the network adapter of course and choose Attached to: NAT. Go to Advanced and pick Intel PRO/1000 MT SERVER as the Adapter Type. This virtual network card will show up as eth2 which we’ve already accounted for in the interfaces file. This NAT adapter will enable the guest to access the internet through the host which is a must to be able to apt-get and wget stuff. Unfortunately it won’t allow you to connect to the guest in a straightforward or normal way like you would connect to any remote machine.
5.) Go to the Adapter 2 tab. This time choose Host-only Adapter and pick vboxnet0 in the Name drop down. Go to Advanced and pick PCnet-FAST III as the Adapter Type.
6.) If this doesn’t work when you subsequently boot up the machine (you have to wait an long time for the networking to sort itself out only to ultimately fail after the 60 second retry, resulting in you being logged in without proper networking) it’s probably because you’re using a different version of VirtualBox. Just do an ifconfig -a and use that information to change the eth2/eth3 to whatever it is that you see in #3. If you have problems determining which is which then shut the machine down, disable Adapter 2, start it back up and redo the ifconfig -a call, now you should be able to understand which is which. Shut down and turn on Adapter 2, start again. And voila you’re done!