VirtualBox Port Forwarding with Windows Host

The first of many ways to handle VirtualBox's virtualization is to Port Forward. Make sure you have the latest of VirtualBox. This allows a person to connect to the virtual machine directly through SSH or view the web server through a browser. Basically, we have the host machine (your actual computer's Operating System) and your guest machine (your virtual machine). This is the Microsoft Windows how to. Here is the GNU/Linux version.

First, you need to go to start menu > run > type in cmd.exe

Then type in the windows host's terminal application:

cd C:\"Program Files"\Sun\"xVM VirtualBox"\

And hit the enter key.

In your windows host's terminal application, run the following commands:

VBoxManage.exe setextradata "name of vm" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
VBoxManage.exe setextradata "name of vm" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage.exe setextradata "name of vm" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP

Before running those commands, replace the following with your personal settings:

  • Replace "name of vm" with your virtual machine
  • Replace ssh with the preferred name you want. This is _required_ to be unique among the three commands.
  • Replace 2222, 22, TCP respectively with your desired host port, guest port, and protocol.

I use port 2222 for the host in this example so it will not conflict on most configurations. This can be replaced with any port setup you desire:

  • Apache (port 80)
  • MYSQL (port 3306 [Update: requires both TCP and UDP])
  • Any many more possibilities

One important note is to make sure you restart all VirtualBox applications (ie. the virtual machine, VirtualBox GUI, all of it). This allows the settings to be used properly.

Once this is done and your virtual machine is restarted, run these commands to verify:

VBoxManage.exe getextradata "name of vm" enumerate

And/or

ssh -l user_name -p 2222 localhost

If you want to clear the virtual machine settings, run this ( Only use this command if you want to clear the settings for this! ):

VBoxManage.exe setextradata "name of vm" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort"

VBoxManage.exe setextradata "name of vm" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort"

VBoxManage.exe setextradata "name of vm" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol"

Enjoy

One Response to “VirtualBox Port Forwarding with Windows Host”

  1. VirtualBox Port Forwarding with Linux Host : Seth Keiper says:

    […] VirtualBox Port Forwarding with Windows Host […]

Leave a Reply

You must be logged in to post a comment.