VirtualBox: Port Forwarding for NAT network
October 29th, 2010 mysurface Posted in VBoxManage, VirtualBox | Hits: 202322 | 8 Comments »
If you came across the solution of setting up port forwarding for ssh port like this:
VBoxManage setextradata [guestname] "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
VBoxManage setextradata [guestname] "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage setextradata [guestname] "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP
You may want to try out this alternative approach. This approach is using the same command ‘VBoxManage’, but it is more flexible and simple.
1. First of all, I power off my guest machine (virtual machine), this approach refuse to work if my guest machine is running.
2. Next, I query my guest machine’s vminfo.
Let say my guest machine ‘s name is ‘gentoo’ (I am gonna use this as example for the entire post) , I will do this:
VBoxManage showvminfo gentoo
It shows a long list of very informative results. I am only interested on my guest machine’s NIC info. Therefore I do this instead.
VBoxManage showvminfo gentoo | grep NIC
NIC 1: MAC: 0800272DC585, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0
NIC 1 Settings: MTU: 0, Socket( send: 64, receive: 64), TCP Window( send:64, receive: 64)
NIC 2: disabled
NIC 3: disabled
NIC 4: disabled
NIC 5: disabled
NIC 6: disabled
NIC 7: disabled
NIC 8: disabled
Based on the result of vminfo, indicates that my guest machine configured a NIC which is NIC1.
Ok, now lets do a port forwarding. Take ssh port as an example. I would like to forward my guest ssh port (22) to my host machine at port (2222). I will do this:
VBoxManage modifyvm gentoo --natpf1 "ssh,tcp,,2222,,22"
The syntax for modifyvm –natpf shows as below:
VBoxManage [guestname] --natpf[1-N] "[function-name],tcp|udp,[hostip],[hostport],[guestip], [guestport]"
‘function-name’ can be any name which well describe the port forwarding rule.
Lets querry the vminfo again.
VBoxManage showvminfo gentoo | grep "NIC 1"
NIC 1: MAC: 0800272DC585, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0
NIC 1 Settings: MTU: 0, Socket( send: 64, receive: 64), TCP Window( send:64, receive: 64)
NIC 1 Rule(0): name = ssh, protocol = tcp, host ip = , host port = 2222, guest ip = , guest port = 22
Observed that I ignore the IP address settings because I am using DHCP on my guest machine NIC.
To delete the port forward rule, I do this:
VBoxManage [guestname] --natpf[1-N] delete [function-name]:
VBoxManage gentoo --natpf1 delete ssh
At last, I boot up my guest machine to verify the port forwarding setting.
VBoxManage startvm gentoo
VBoxManage can do more than just port forwarding, check it out the manual if you want to know more.
Hope you enjoy.
December 29th, 2010 at 5:10 am
Take a look at http://code.google.com/p/phpvirtualbox/. I set it up last week and it is awesome!
July 7th, 2013 at 11:13 am
?????? ?????????????????????????????
August 13th, 2014 at 12:33 pm
Soci societe p restaurationSoci societe nufactured restaurationIls se nomment Pierre N’Gahane, tanker Lozès, Lionel Zinsou. took on Dieng, Pape Diouf, Rougui Dia, Pascal Agboyibor Gaston Kelman, Mohamed Dia, Safia Otokoré, Fode Sylla, Kofi Yamgnane. Certains sont connus du large customer, D’autres moins. HAUTs ALpBS. mm. a. assuming we do decide to do this, this is am i right. a few things i am scared of that is air max fille smidgen of piece of your coronary heart that will participat
November 9th, 2014 at 5:59 am
Excellent goods from you, man. I’ve understand your stuff previous to and you are just extremely fantastic.
I actually like what you have acquired here, certainly like what
you’re saying and the way in which you say it. You make it enjoyable and
you still take care of to keep it smart. I cant wait
to read far more from you. This is actually
a terrific web site.
December 22nd, 2014 at 2:53 am
Thanks for sharing your thoughts about linux by example.
Regards
August 18th, 2016 at 12:27 am
Passion the website– very individual pleasant and great deals to see!
nhl 17 http://amusecandy.com/blogs/post/72623
September 7th, 2018 at 2:22 pm
excellent put up, very informative. I ponder why the opposite specialists of this sector do
not understand this. You must proceed your writing.
I’m confident, you have a huge readers’ base already!
December 29th, 2018 at 9:44 am
Unquestionably believe that which you said.
Your favorite justification appeared to be on the net the simplest thing to be aware of.
I say to you, I definitely get annoyed while people think about worries that they just don’t know about.
You managed to hit the nail upon the top as well as defined out the whole thing without having side effect , people
can take a signal. Will likely be back to get more.
Thanks