Seth Keiper

VirtualBox Port Forwarding with Windows Host

by on Aug.17, 2008, under VirtualBox, Virtualization

Make sure to read the VirtualBox User Manual for the latest methods as this post is 99% outdated.

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


2 Comments for this entry

  • Filipe Marques

    Seth, I have some doubts about this command. On what type of VBox network will it work for? NAT, Bridge?

    The other question is: If perhaps my ethernet card on my linux guest os is set up to eht1 and not eth0 I have to change only the "/0/" or I have to change the LUN#0 parameter too?

    • Seth Keiper

      Seth, I have some doubts about this command.

      When in doubt, read the VirtualBox User Manual. Also, remember that these post about VirtualBox was published on August 17, 2008. That is 2 and half years ago (roughly) and I wrote this for VirtualBox 1.6.4. Things change very rapidly in the world of VirtualBox. As of this comment writing (2011-04-02), we are on VirtualBox 4.0.4. Thousands of revisions. Always, rely on the VirtualBox User Manual.

      On what type of VBox network will it work for? NAT, Bridge?

      NAT

      The other question is: If perhaps my ethernet card on my linux guest os is set up to eht1 and not eth0 I have to change only the "/0/" or I have to change the LUN#0 parameter too?

      With VirtualBox NAT, it doesn't care what your host network adapter is. Read this chapter of the User Manual. Also, most likely, you want Bridged Networking and not NAT with Port forwarding.

      Do note that the anchors in these URLs that are within these links are subject to change as the User Manual is changed and exanded due to how doxygen regenerates anchors.

3 Trackbacks / Pingbacks for this entry

Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!