I regularly use VirtualBox, which allows you to set up and run virtual machines (VMs) on
your own desktop. It’s a very nifty bit of software, but one drawback is that
by default, the guest VM is invisible to the host or any other
machines on the network. You can’t, for example, access the Web server on your
guest from the host.
Tip of the Trade: VirtualBox makes it easy to set up and run virtual machines on your own desktop. It is not perfect, however, and by default, the guest VM is invisible to the host or any other machines on the network. Here’s an easy way to relay instructions to it.
Happily, there is a way of proxying specific connections, using the
VBoxManage tool. To forward ssh on one guest, I used the following commands:
VBoxManage setextradata "Debian Lenny" " VBoxInternal/Devices/pcnet/0/LUN#0/Config/virtualssh/Protocol" "TCP"VBoxManage setextradata " Debian Lenny" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/virtualssh /HostPort" 5000 VBoxManage setextradata "Debian Lenny" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/virtualssh/GuestPort" 22
These commands all apply to the guest named “Debian Lenny” and to the
connection virtualssh –. This is an arbitrary identifier, so you
can create multiple port forwards by using different names. After issuing
these commands, all TCP connections to port 5000 on the host will be
forwarded to port 22 on the guest. And you can now ssh into your guest
A couple of notes: Firstly, the guest must be switched off when
you issue the commands. Secondly, presumably for security reasons, the
forwarding doesn’t appear to last between iterations of VirtualBox –
each time you quit VirtualBox, you’ll need to reissue the commands when you
start it back up again. If you’re doing this regularly, you’ll want to put
the lines above into a shell script and run that when required.
Juliet Kemp has been messing around with Linux systems, for financial reward and otherwise, for about a decade. She is also the author of “Linux System Administration Recipes: A Problem-Solution Approach” (Apress, 2009).