Accessing a VirtualBox guest over ssh

This goes over to the right of the geek-o-meter. I’ve been swimming virtualization lately: openvz, VirtualBox, and most recently, Amazon’s S3/EBS/EC2. For quick test projects, I really like VirtualBox running on my mac. However, I ran into a small hiccup: I needed to have a NAT’ed RedHat box running inside of VB. I need to be able to ssh into that box from the host Mac. I located an excellent blog entry that solved this issue here.

I went one step further and wrapped the statements from the blog post into a tiny script:


#!/bin/bash
GUEST=$1
HOSTPORT=2222
GUESTPORT=22
USERNAME=root
if [ -z ${GUEST} ]
then
echo 'Need VirtualBox machine name to forward ports to...'
exit 1
fi
VB="/Applications/VirtualBox.app/Contents/MacOS/VBoxManage"
${VB} setextradata ${GUEST} "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" ${HOSTPOR
T}
${VB} setextradata ${GUEST} "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" ${GUESTP
ORT}
${VB} setextradata ${GUEST} "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP
echo "Done... Issue Command:"
echo "ssh -l ${USERNAME} -p ${HOSTPORT} localhost"

I hope you’ll find it useful. Be careful of line-wraps in the code; one of these days I will add in one of those code highlighter things.

More next week about our experiments in Amazon-land!

Reblog this post [with Zemanta]
Advertisements