WSL: Single WSL2 localhost port can't be accessed from Windows side

Environment

Windows build number: 10.0.19041.0
Your Distribution version: Ubuntu 20.04
Whether the issue is on WSL 2 and/or WSL 1: Linux version 4.19.84-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Nov 13 11:44:37 UTC 2019

Steps to reproduce

  1. Create and start a new create-react-app app:
npx create-react-app my-app
cd my-app
npm start
  1. Try to access it from the browser using the localhost address: localhost:3000 -> The browser can’t connect
  2. Re-start the app by specifying a different port PORT=3001 npm start -> The browser can connect

Further details

I expect that this is due to specific configuration on my machine, but I don’t know what is wrong. I disabled Windows Firewall and it still doesn’t work. Fast Startup is turned off. Accessing the react app through the ip address + port works as expected. Restarting Windows and WSL 2 (multiple times) did not help.

I assume that this issue is similar to issues #5497 and #5298, but I can access servers that are running on different ports (e.g. 5000, 8080, 3001, etc.).

Any workaround would be appreciated. If possible I would like to not need to get into the insider program again, I am hoping I can stay on the stable 2004 version.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 18

Most upvoted comments

Just in case it happened to someone else and there were no such ports open during in-windows inspection, but inside WSL port was listened: it helped me simply to restart WSL by wsl --shutdown {name} and starting it then again.

Thanks a lot for the help. 👍 🙏

It appears that the IP Helper service was the culprit and after disabling it the port worked again. I assume this did not have anything to do with WSL 2 then, therefore I’m closing the issue.

wsl --shutdown

This solved my issue, thank you

IP Helper service Turning off IP helper was the solution for me!

What Ono said. Or from powershell, using TCP port 5040 as example, which is the Connected Device Platform Service

PS C:\> (Get-WmiObject -Class Win32_Service | where ProcessId -eq (Get-Process -Id (Get-NetTCPConnection -LocalPort 5040).OwningProcess).Id).Name

image

Ive tried a bunch of other things, but I had to disable IP Helper service to be able to access my stack on localhost:4200 on windows 11, wsl2. weird that this seems to be the issue, i dont think I had this problem with win 10 or running natively on ubuntu. Seems to the same issue as this fella was having too I wonder if there is some conflict here with the service that needs a more serious look at.

Easy enough, and safe enough to disable the service through GUI least source:

  • launch the build in services app, by searching for services app in the windows search
  • navigate/scroll down to IP Helper
  • disable the service, and set its startup type to disabled
  • reboot

Open PowerShell and post the output of: netsh int ipv4 show excludedportrange protocol=tcp

netsh int ipv4 show dynamicport tcp