Muffinresearch Labs by Stuart Colville

Howto: SSH into VirtualBox 3 Linux Guests | Comments (5)

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.

screenshot showing virtualbox guest adapter2 being configured to use host-only networking

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.

Post Tools

Comments: Add yours

1. On February 8th, 2010 at 1:15 pm VirtualBox: Access Guests via a Virtual Interface by Stuart Colville said:

[...] If you’re using VBox 3.x then Howto: SSH into VirtualBox 3 Linux Guests is more up to [...]

2. On February 26th, 2010 at 5:17 pm Jason said:

Where did you get the “address 192.168.56.10″ line from?

3. On February 26th, 2010 at 5:25 pm Stuart Colville said:

@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.

4. On February 27th, 2010 at 5:21 am Jason said:

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 :)

5. On February 27th, 2010 at 5:35 am Jason said:

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.







XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Using Loggerhead with mod_wsgi|(0)

Here’s a post I wrote over on the Project Fondue Blog about our use of Loggerhead with mod_wsgi under Apache. Loggerhead is the rather nice branch viewer for bazaar branches as used on Launchpad.net.

If you’re not already subscribed to the Project Fondue blog feed then I can recommend it, as there should be some interesting posts coming out of there in the coming months (yes I’m unashamedly biased!).

Ubuntu: Turn off changing workspace with mouse wheel|(1)

I found the changing with the workspace with the mouse wheel really annoying. To disable it go to System => Preferences => CompizConfig (available if the compizconfig-settings-manager package is installed) and uncheck “Viewport Switcher” which is under the “Desktop” heading.

Photos on Flickr

© Copyright 2004-10 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by Slicehost.com This page was baked in 0.636s.