How to port forward to Virtual machine?

Caporegime
Joined
25 Jul 2005
Posts
28,851
Location
Canada
I have a couple of ports that need port forwarding to my virtualbox for them to work properly, can anyone tell me how to do this? I've looked online but am still confused.

I've found http://sk.c-wd.net/wp/2008/08/17/virtualbox-port-forwarding-with-windows-host/ that I think explains it however I'm a little confused.

Firstly the main machine runs Vista and is attached to the router (port 200 is forwarded to it and works), now I want to forward the same port to the VM (XP in this case) for a program to run properly on it.

Now following that I open cmd in vista and type

cd C:\"Program Files"\Sun\"xVM VirtualBox"\ (which is the location of the folder right) Then type in

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

all of that (changing the custom bits)? The name of the VM is I guess just "XP" in this case (name of the folder?)

Now the main confusion is the host port and the guest port. I assume the host port is the port Vista is attached to the router (and the router open for) and the guest port the port the program needs (? Again say port 200) Can I run the same port straight through (eg have router, host, guest and program all port 200) and if so will this affect the program on the host PC?

Sorry, long and convoluted post but i'm a bit confused.:p
 
I can't really help with that side of things, as before your post I didn't even know you could do that! I'm just posting to suggest you might assign the VM a static IP on your LAN, and forward ports in the router itself. Is that a possibility for your circumstances? Unless the VBoxManage.exe app lets you forward ports to more than one IP (which you can't do in a router obviously) then I see no reason not to do it the old-school way.
 
I've tried that but haven't been successful. I got the IP address of the virtual OS using ipconfig on the host (Vista)

Ethernet Virtual adaptor IPv4 Address 192.168.56.1

and then sticking that ip and the port I want into the router. However the port isn't open, this is without the same port being forwarded to the host (Vista).
 
Isn't 192.168.56.1 the IP of the actual VB virtual network? It's on the .56 subnet whereas I'm presuming your router is something more like 192.168.1.1 or 192.168.0.1 etc? The IP the VM is given can be set in the router, for example 192.168.1.150 (outside of DHCP range). From there, you can verify the VM picks up the IP on boot and then forward the ports to it inside the router.

I may be wrong but it seems to me you're currently trying to forward ports to VirtualBox itself there.

EDIT: To clarify... There may be other ways of doing it, but I set the VM/guest to have bridged access to the host's network adapter. That way it gets issued a DHCP IP from the router as if it was a 'real' machine on the network. If you use VB's own adapter, it generates an IP based on VB's own virtual network (ie 192.168.56.x) which precludes you from easily forwarding ports in the router. The router won't understand what to do, as the .56 subnet is effectively out of its sights.

By using a bridged (to your host machine's NIC) connection, you effectively place the guest onto the 'real' LAN and thus can play around with ports and static IPs to your heart's content. I hope this was in some way useful. Good luck. :)
 
Last edited:
this thread is far too complicated. just setup bridged networking in the settings for your virtual machine. then you can treat it as a real machine as mentioned above. easy. :)
 
Yep, did that and it sorted it instantly :o

I got confused by VB's own network... Ports are now forwarding freely, thanks guys. :D
 
Bumpidy bump...

Gah! For some reason my Virtualbox install decided to play up yesterday, even going back to snapshots didn't work. Anyway everything was saved so I started a new one and reinstalled XP on it. All fine until I try and port forward again...

capturetf.png


Now can someone tell me why the VirtualBox host only network has no network access? The internet works on it, I just can't port forward to it... I've bridged the connection to the main Marvell Yukon connection but the connection isn't visible to my router. Am I missing something obvious?

Thanks
 
Back
Top Bottom