Guides Setting Up Tunneling With a VirtualBox Guest Machine

Setting Up Tunneling With a VirtualBox Guest Machine




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
machine!

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

Follow ServerWatch on Twitter

Latest Posts

Compare HP’s iLo & Dell’s iDRAC Server Management Tools

Most servers shipped from the major manufacturers today come with some type of out-of-band management tool or baseboard management controller (BMC). Two of the...

Get-MsolUser PowerShell Attributes & Properties

This article has been updated for 2020. Please note that WAAD was retired in 2018, but the cmdlets listed in this article are still...

Microsoft Azure PowerShell Scripts and Commands

Using PowerShell scripts and commands for quickly executing tasks in Windows operating systems offers a number of benefits over traditional scripting languages, such as...

Microsoft Hyper V Review

Microsoft Hyper-V: The Bottom line Microsoft Hyper-V lagged behind VMware's virtualization tool, one of the most popular tools in the space, when it was first...

Best Cloud Based Services & Companies

Any company that’s delayed introducing cloud-based software into their infrastructure needs to consider leveraging these new technologies to reap all the benefits cloud computing...

Related Stories