MicrosoftDocs / WSL

Source code behind the Windows Subsystem for Linux documentation.
https://docs.microsoft.com/windows/wsl
Other
1.88k stars 554 forks source link

Netsh portproxy snippet unclear when forwarding traffic into WSL 2 #1890

Open rudah-amaral opened 6 months ago

rudah-amaral commented 6 months ago

Documentation Issue

Currently on WSL 2 it's necessary to add a port proxy with PowerShell in order to access servers running on it in your LAN. This relevant section on the docs has the following snippet

netsh interface portproxy add v4tov4 listenport=<yourPortToForward> listenaddress=0.0.0.0 connectport=<yourPortToConnectToInWSL> connectaddress=(wsl hostname -I)

Suppose I'm running a Vite server and want to have access to it on my LAN. If I substitute the ports in this snippet with 5173 and run it, checking afterward said rule with netsh interface portproxy show v4tov4 will show it was created successfully, with the connectaddress variable being resolved to my WSL 2 network adapter IP.

But it won't work. If I first run wsl hostname -I and then substitute this IP into the snippet too, the traffic will be forwarded as expected.

Link to documentation page

https://learn.microsoft.com/en-us/windows/wsl/networking#accessing-a-wsl-2-distribution-from-your-local-area-network-lan

Suggested Improvements

What I personally think is confusing is that executing the snippet substituting only the ports won't fail. Even checking said rule afterwards will show the WSL machine IP as if the command was successful, even if it won't actually work. This may lead users to think this step was done correctly and the reason they can't connect to their server by their LAN was because of something else, incorrect firewall rules for example.

Maybe if the connect value was between <> as well as the ports and wsl hostname -I was introduced before, it would make it clearer to the user that they are supposed to first to get the machine IP and then substitute it into the snippet, as they did with the ports.

jsnedeco commented 2 months ago

THANK YOU! I no joke spent about four hours on this. I could not for the life of me figure out why none of the traffic on my port was being forwarded to WSL2 (I checked in Wireshark) and googled a million irrelevant things before I found this. The worst thing is that the rule looks identical when I do "netsh interface portproxy show all" the only difference is IT WORKS.

rudah-amaral commented 2 months ago

I know, it's maddening. I'm glad opening this issue could help someone else.