79327668

Date: 2025-01-03 21:00:18
Score: 0.5
Natty:
Report link

Try another port number

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

Results:

<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:

  1. Open this port on my machine. For a reasonably "how to" explanation see this: https://support.warriortrading.com/support/solutions/articles/19000113122-how-to-open-ports-in-windows-10-and-windows-11-firewall
  2. Forward the port:
netsh interface portproxy set v4tov4 listenport=25001 listenaddress=* connectport=25001 connectaddress=wsl

WARNING: Opening the port seems to be immediate, but forwarding the port can take a few moments.

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:

  1. You can connect to ports running in WSL via localhost on your machine with no configuration. But there seem to be ports that do not automatically work, avoid them.
  2. If you want to access your WSL port from outside your Windows machine you will need to:
Reasons:
  • Blacklisted phrase (0.5): I need
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: BruceJo