0

I am working on windows machine and using netsh portproxy to forward traffic from port 4000 to application running on port 4002. It works fine when trying to access my application from localhost or LAN, like this

127.0.0.1:4000
192.168.1.21:4000

However when I connect outside of my LAN port forwarding doesn't seem to work at application doesn't see requests target at my.public.ip.address:4000. What is the reason for this behavour? Note that when I remove port proxy and run my application at port 4000, requests targeted at my.public.ip.address:4000 reach my app without a problem. Here's my current netsh portproxy configuration:

netsh interface portproxy show all

Listen on ipv4:             Connect to ipv4:

Address         Port        Address         Port
--------------- ----------  --------------- ----------
0.0.0.0         4000        127.0.0.1       4002
  • What is the topology of your network? Do you have a router with firewall? Why not use that firewall to configure port forwarding? – Mircea Vutcovici May 15 '21 at 13:00
  • @MirceaVutcovici I have used my router port forwarding to get traffic for port 4000. The problem is I eventually want to redirect requests to wsl2 and therefore I'm forced to use netsh. This seemed irrelevant to this problem, as I found out redirects doesn't work even within windows and posted minimalistic version not to complicate this too much. I would like to find out why this particular configuration doesn't work. – user5249875 May 15 '21 at 14:12
  • @MirceaVutcovici Also correct me if I'm wrong but I think that netsh port proxy bound on address 0.0.0.0 should redirect requests coming from WAN as 0.0.0.0 listens on every interface, do you have any idea why doesn't it work as expected? – user5249875 May 15 '21 at 14:15

2 Answers2

0

For WSL2 port forwarding, you need to write a small script that basically invokes netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport with right parameters.

See:

Mircea Vutcovici
  • 17,619
  • 4
  • 56
  • 83
  • That's what I did, it's not forwarding my requests, and that's why I created this question – user5249875 May 15 '21 at 15:58
  • You can literally see in configuration that I posted that port forwarding is set up in this manner from port 4000 to 4002, it doesn't forward requests that are not comming from my local network – user5249875 May 15 '21 at 16:00
  • Also I removed your wsl tag from question, as I don't have problem with accessing wsl, only with netsh not forwarding WAN requests. In situation I posted it doesn't work in windows only environment – user5249875 May 15 '21 at 16:14
0

Apparently it wasn't working due to windows firewall, this solved it for me netsh advfirewall firewall add rule name="Open Port 4000" dir=in action=allow protocol=TCP localport=4000