Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rudah-amaral opened this issue Jan 2, 2024 · 3 comments
Open
Assignees

Comments

@rudah-amaral
Copy link

rudah-amaral commented Jan 2, 2024

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
Copy link

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
Copy link
Author

rudah-amaral commented May 3, 2024

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

@palapapa
Copy link

palapapa commented Sep 15, 2024

OMGGGGGGG TYSM!!!!!!!

I thought that syntax was weird at first, but I ignored it. It turns out that the syntax for command substitution in Powershell is also $(). It's very strange that the command would accept (wsl hostname -I) as a valid argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants