Howto: SSH into VirtualBox 3 Linux Guests | Comments (9)
Posted in Code, Linux/Unix on 8th February 2010, 1:11 pm by Stuart
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:
ssh jeos@192.168.56.10
That’s it.

[...] If you’re using VBox 3.x then Howto: SSH into VirtualBox 3 Linux Guests is more up to [...]
Where did you get the “address 192.168.56.10″ line from?
@Jason that’s just made up based on the settings for the vboxnet0
In other words to know what ips you can use for each vm look at what vboxnet0 is set to by running ifconfig on your host.
For me it’s defaulting to 192.168.56.1 so that tells me I can choose any IP address from 192.168.56.2 onwards.
Thanks for explaining
Networking magic numbers are not my strength…
I got this working under Debian Squeeze (host and guest), but for some reason “ifup eth1″ was not enough, it seemed to require a reboot of the guest.
This is excellent, now I can test webserver magic without cluttering up my actual PC. Thanks for the writeup
Okay, the problem was actually Firestarter on the HOST side (the iptables based firewall manager), that I happened to switch off at about the same time as rebooting the guest.
See:
http://osdir.com/ml/security.firewalls.firestarter.user/2006-04/msg00023.html
…but Firestarter is not really designed to deal with multiple interfaces.
You rock, thanks for this tutorial. I was working on getting Debian set up through VirtualBox as a sandbox for work, then I realized I had no idea how to access the guest os from my host. So, thanks!
Perfect explanation. Btw this also works on a windows 7 host. Obviously to check the vboxnet0 prefered ip on windows instead of using ifconfig -a you use ipconfig /all but I think virtualbox 3up defaults to 192.168.56.1 anyway, so that leaves you with the choice of any number in the range of 192.168.56.2-192.168.56.255
Alternatively instead of using the command prompt, in vista and 7 you can use powershell. Powershell accepts most standard linux commands, making cli on windows much less frustrating.
PS, add the guest machine’s ip and name to your host machine’s hosts file to ssh from the host to the guest by name instead of ip.
So if your username is bobby and your guest machine’s name is tintin and its ip is 192.168.56.10, adding the line
192.168.56.10 tintinto hosts (on the host machine) will allow you to access the guest from the host like so:
ssh bobby@tintinThanx! works fine for me and it was very simple.
I wasted a lot of time doing the wrong way before I reach this howto!
cheers