In a previous post I wrote about using a TAP interface to be able to SSH into linux guests from the host. Since then changes in the newer versions of VirtualBox have seen the addition of a virtual interface on the Host by default. This post details how to utilise this to allow communication from your host to your guests by simply configuring a second network interface on the guest.
Note: the same result can be used by using one bridged interface to a physical network interface. However, I prefer to do it this way as I'm using a laptop and I don't know at what point I'll be using a wired, wireless or 3G connection. The following config will always work irrespective of where you are. That said feel free to detail any experiences of alternative methods in the comments.
The following assumes you are using Linux as a host.
The process is very straightforward if you already have a linux VM or if you are creating one from scratch the process is essentially the same note if you are doing this prior to installing an OS the only thing to note is which interface should be your primary interface. In most case this should always be the NAT adapter. Here's a screenshot showing the dialogue you'll see when installing JEOS as an example.
All you need to do is access the settings when the guest is off and add a second network interface to the guest. By default you should have one interface already which is using NAT. This should be left alone as this provides access to the internet. Select the tab "Adapter 2" and change "attached to" to "Host-only Adapter" this will have the name vboxnet0 by default.
Once that's set, boot the Guest image.
Once booted; from the console of the guest VM you'll need to set-up the configuration for the second network interface in this case
eth1 as we already have
eth0 defined. To do this all you need to do is edit
/etc/network/interfaces to add the eth1 configuration.
This is a simple as adding the following lines based on our vboxnet0 is configured to 192.168.56.1 (based on running ifconfig on the host.
auto eth1 iface eth1 inet static address 192.168.56.10 netmask 255.255.255.0
Save this and then run the following to fire up eth1:
sudo ifup eth1
Note: If you haven't already installed openssh-server now would be a good time to do so!
sudo apt-get install openssh-server
Now you can drop into the terminal and ssh into your VM e.g: