VirtualBox Port Forwarding with Linux Host
by Seth Keiper on Jan.05, 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). So far, this is only for GNU/Linux host how to. Later the windows host how to will be added. Here is the Microsoft Windows how to.
In your GNU/Linux host's terminal application, run the following commands (Warning: make sure the quotes are proper quotes due to this CMS' protection from quotes Update: this quotation issue has been fixed the quotes you see should work):
VBoxManage setextradata "name of vm" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
VBoxManage setextradata "name of vm" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage 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 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 setextradata "name of vm" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort"
VBoxManage setextradata "name of vm" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort"
VBoxManage setextradata "name of vm" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol"
Enjoy
2 Comments for this entry
4 Trackbacks / Pingbacks for this entry
-
BySus Gedankenwelt » Post Topic » Port Forwarding in VMs - Virtual Box
March 16th, 2008 on 09:39:37[...] liegen könnte. Und so schmökerte ich ein wenig nach Port Forwarding unter Virtualbox bis ich auf diesen Artikel stieß. Hier nun der Code, der konkret benötigt wird, um unter der VM Port Forwarding zu [...]
-
VirtualBox Port Forwarding with Windows Host : Seth Keiper
August 17th, 2008 on 15:27:13[...] VirtualBox Port Forwarding with Linux Host [...]
-
Virtualbox port forwarding on a Linux Host
October 17th, 2008 on 15:38:22[...] excellent article on the subject: Source. VBoxManage setextradata "name of vm" [...]
-
BySus Gedankenwelt » Blog Archive » Port Forwarding in VMs - VirtualBox
April 6th, 2009 on 05:58:14[...] liegen könnte. Und so schmökerte ich ein wenig nach Port Forwarding unter Virtualbox bis ich auf diesen Artikel stieß. Hier nun der Code, der konkret benötigt wird, um unter der VM Port Forwarding zu [...]
March 7th, 2011 on 21:03:49
Is this post relevant to VirtualBox 4.0.4? I am using Fedora 14 as the host and Windows XP in VirtualBox. I have added two ports (TCP and UDP) to the firewall settings in 'other ports' in fedora? Do i need to do this?
I noticed the port forwarding option in the firewall setup which asks for either the ports to be forwarded to either local or an ip address. Do i need to do anything here?
In the settings under VirtualBox under Network adapter 1 (which is enabled) and attached to NAT, there is a port forwarding option in the advanced setings. Can the host and the guest port be the same be the same number? If i use 'open port checker' to check if the tcp port is open in firefox under windows xp in virtualbox will it work as it does in Fedora? I have added the 2 ports to windows firewall.
March 21st, 2011 on 22:50:41
Yes and No. Depends on your taste but always read the VirtualBox User Manual.
You can use the GUI just as well. It was added to remove ambiguity.
You probably would want a local IP.
No
with any GNU/Linux distro (which fedora is included in), I would suggest to either use netstat or nmap. Your choice.