VirtualBox Port Forwarding with Windows Host
by Seth Keiper 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
3 Trackbacks / Pingbacks for this entry
-
VirtualBox Port Forwarding with Linux Host : Seth Keiper
August 17th, 2008 on 15:29:26[...] VirtualBox Port Forwarding with Windows Host [...]
-
[Help] Port Forwarding need help - RaGEZONE - MMORPG server development forums
April 4th, 2010 on 06:28:32[...] coded to look like they from another NIC mac.I know most routers wont pick this up. try this method http://sk.c-wd.net/wp/2008/08/17/vir…-windows-host/ if not look for "portforward vbox or [...]
-
Chris’s Digital Detritus » VirtualBox Port Forwarding with Windows Host – Seth Keiper
May 17th, 2010 on 01:20:30[...] VirtualBox Port Forwarding with Windows Host – Seth Keiper. Categories: Tidbits Tags: Comments (0) Trackbacks (0) Leave a comment Trackback [...]
March 31st, 2011 on 14:48:05
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?
April 2nd, 2011 on 19:15:15
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.
NAT
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.