Page 1 of 1

Port forwarding

Posted: 21. May 2020, 13:08
by JackoBox
Can't seem to find a guide on setting up port forwarding, can anyone help?

I'm running guest XP in virtualbox from my host PC running Win10.
From the guest XP, I want to run software that communicates with industrial equipment via network.

I believe this is achieved using port forwarding, and I have tried, but cannot ping from an external pc to guest (I can ping from external to host).

Any help appreciated. cheers

Re: Port forwarding

Posted: 21. May 2020, 14:21
by scottgus1
See Virtualbox Networks: In Pictures

The two Virtualbox networks that have port forwarding are 'NAT' and 'NAT Network'. Both behave like house routers

A router makes a private network for your computers and has the internet on the other side. The computers can get to anything on the internet, but port forwarding is necessary when something on the internet wants to get to the computers.

For a NAT or NAT Network guest, the guest itself is the private computer, and the host, the other computers and devices on the host's network and the internet, are all accessible to the guest with no port forwarding needed. If you always start the communication to the industrial equipment from inside the guest, then you should not need to port-forward. The equipment is part of the "internet" to the NAT guest.

If the equipment needs to start communication into the guest first, that would require port forwarding on the NAT adapter that the guest has, since it is like something on the internet trying to get into your private computer.

Each NAT adapter has its own port forwarding section in the Advanced dropdown. Each NAT Network has a port-forwarding section in the main Virtualbox window's File menu, Preferences, Network, doubleclick the NAT network. The above tutorial shows what data is needed for NAT or NAT network. For NAT you need only the Host Port and Guest Port. Host Port is what port number the outside equipment tries to communicate through. Guest Port is what port the guest expects the traffic to come on.

Example 1: I have a NAT-connected Windows Pro guest with Remote Desktop (RDP) active. The Windows OS wants RDP on port 3389. So I would set the Host and Guest ports in the Port Forwarding for the guest's NAT adapter both to 3389. No other information is needed in the Port Forwarding setup. I access the guest RDP by host.ip.add.ress:3389

Example 2: Same setup as Example 1, except the host also wants to use 3389 for its RDP. I cannot distinguish which PC, host or guest, I would remote into if they both have 3389. So I set my guest's NAT Port Forwarding to Host port 3390, guest port 3389. Now RDP on 3389 goes to the host PC, and RDP on 3390 goes to the guest. No other information is needed in the Port Forwarding setup. I access the guest RDP by host.ip.add.ress:3390, and I access the host RDP by host.ip.add.ress:3389

Example 3: Same as Example 1 except the guest uses NAT Network. In addition to the Host and Guest Ports, i must also provide the IP address the guest receives from the NAT network. If NAT Network gives my guest 10.0.2.16, then I must provide Host port 3389, Guest port 3389, Guest IP address 10.0.2.16. Nothing else needed. I access the guest RDP by host.ip.add.ress:3389

Example 4: Same as Example 2, except connected through NAT network. Host Port 3390, Guest Port 3389, guest IP 10.0.2.16. Nothing else needed. I access the guest RDP by host.ip.add.ress:3390, and I access the host RDP by host.ip.add.ress:3389

An easier way to set this up without any need for port forwarding is to use Bridged for the guest. The guest then sits in the host network along with the host and equipment, and all devices can talk to each other. (If you are worried about XP trying to access the internet, you should be able to block the XP "computer" using your network router's Access Restrictions or Parental Controls page.

Re: Port forwarding

Posted: 22. May 2020, 11:20
by JackoBox
Hi Scottgus1,

Thank you so much for your very detailed response to my problem.
From your explanation, I now think that I don’t need to use port forwarding, because the communication to the industrial equipment will always be started from inside the guest.

I am still struggling to get this network to behave as I want! I hope you can help shine a light on what I must be doing something wrong somewhere!

Here is the background: (Host=Win10, Guest=WinXP)
I can run the setup using bridged mode and everything works fine! I can ping from the guest (192.168.49.238) to host (192.168.49.239). I can also ping another laptop on the network connected by wire (192.168.49.11). HOWEVER, this method uses up two I.P. addresses 238 & 239, and this is already a very crowded external network (I will be adding 6 more laptops setup identically and this will add 2 more I.P. addresses each), so I want the setup to only use one I.P. address for each laptop.

If I change the guest network setting to ‘NAT’:
I cannot ping from the guest (192.168.49.238) to host (192.168.49.239)
I expect virtualbox to change the guest I.P. to 10.0.2.15, so I try to ping 10.0.2.2 and also try 10.0.2.15 BUT always get the message ‘destination host unreachable’.
If I manually change the guest network connection I.P. address to 10.0.2.15 (using guest windows XP network connections), then I get a reply from both 10.0.2.2 & 10.0.2.15, however I cannot then ping to the host machine 192.168.49.239 or the machine on the network 192.168.49.11

It seems I must be missing something?

Your help is much appreciated.

Kind regards, Jack

Re: Port forwarding

Posted: 22. May 2020, 21:30
by JackoBox
H Scottgus1,

I found a solution!

I had to enable a second adapter in VirtualBox network settings (set to NAT), and disable the first adapter.

Everything works fine now!!!

Thanks again for your help :D

Re: Port forwarding

Posted: 24. May 2020, 01:35
by scottgus1
Glad you got things running!

Re the new NAT adapter now working: It probably is back to default configuration. Networking has a lot of places where attempting to solve a problem can leave the setup in a hopelessly-misconfigured state, and a fresh start is good.

NAT is like a router, and while you can ping from the guest to anything on the host, LAN or internet, you cannot ping from the host or LAN into the guest.