I tried everything in this thread to forward to port 50111
, which I was doing without issue on Windows 10. I could only connect to it by using the wsl address directly.
Get your hostname:
<WINDOWS CMD PROMPT>$ wsl.exe hostname -I
172.20.48.194 172.17.0.1
For this example, I will use my host IP:172.20.48.194
, remember to substitute your host IP.
Add a rule in C:\Windows\System32\drivers\etc\hosts
172.20.48.194 wsl
<WINDOWS CMD PROMPT>$ curl http://localhost:25001
--- WORKS: got expected output
<WINDOWS CMD PROMPT>$ curl http://localhost:50111
curl: (7) Failed to connect to localhost port 50111 after 2208 ms: Could not connect to server
Lesson: try other port numbers. There is some information out there referring to ports past 50000 as ephemeral ports used mostly for output.
This was all without any port forwarding. However, if I want to refer to my own IP (instead of localhost), I get this:
curl http://192.168.1.100:25001
curl: (7) Failed to connect to 192.168.1.100 port 25001 after 2035 ms: Could not connect to server
To fix this I needed to do 2 things:
netsh interface portproxy set v4tov4 listenport=25001 listenaddress=* connectport=25001 connectaddress=wsl
Wait for a little bit before testing less than 2-3 minutes at most.
After opening the port:
<WINDOWS CMD PROMPT>$ curl http://192.168.1.100:25001
--- WORKS: got expected output
So:
WSL
via localhost
on your machine with no configuration. But there seem to be ports that do not automatically work, avoid them.