Port Forward and Expose on Windows OS



Expose port, open PowerShell run as administrator

$ New-NetFirewallRule -Name db2port50000 -DisplayName 'db2port50000' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 50000


Check first list avalability, open cmd run as administrator.

$ netsh interface portproxy show all


If there was available active port, kill before re-forward port.

$ netsh interface portproxy delete v4tov4 listenport=50000 listenaddress=0.0.0.0


Re-add previous port.

$ netsh interface portproxy add v4tov4 listenport=50000 listenaddress=0.0.0.0 connectport=50000 connectaddress=127.0.0.1

-----     -----     -----     -----     -----     -----     -----     -----     -----     -----

Special case :

I have a virtual machine on cloud and personal computer that actively connect to internet.

On my PC there was a DB2 installed with port 50000.

So, when I'm not at office. How can I connect to DB2?

The solution one is by using SSH.

Here is the ssh script, enable your local port to be established via virtual machine on cloud.

$ ssh -nN  -R remote_port:127.0.0.1:local_port -i .ssh\private_key usrdebian@ip_public -p ssh_port

Comments