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

Single WSL2 localhost port can't be accessed from Windows side #5575

Closed
peterjuras opened this issue Jul 11, 2020 · 17 comments
Closed

Single WSL2 localhost port can't be accessed from Windows side #5575

peterjuras opened this issue Jul 11, 2020 · 17 comments
Labels

Comments

@peterjuras
Copy link

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.

@onomatopellan
Copy link

onomatopellan commented Jul 11, 2020

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

netsh int ipv4 show dynamicport tcp

@peterjuras
Copy link
Author

C:\Users\pjura> netsh int ipv4 show excludedportrange protocol=tcp

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
      5357        5357
     50000       50059     *
     55651       55750
     55751       55850
     55991       56090
     56091       56190

* - Administered port exclusions.
C:\Users\pjura> netsh int ipv4 show dynamicport tcp

Protocol tcp Dynamic Port Range
---------------------------------
Start Port      : 49152
Number of Ports : 16384

@onomatopellan
Copy link

thanks, tcp dinamic assignation is not the problem then.

Try HOST=0.0.0.0 npm start and see if localhost:3000 works

@peterjuras
Copy link
Author

No, sadly HOST=0.0.0.0 npm start does not work.

@onomatopellan
Copy link

In Resource Monitor -> Network tab- > Listening ports can you see if there is an exe listening on port 3000?

@peterjuras
Copy link
Author

Thanks for helping!
Yes it listing a process, although I have neither anything open with port 3000 or 3100. I also can't find any firewall rule which restricts port 3000 🤔

This is a screenshot of the resource monitor view: https://imgur.com/8qTO4Q6
Annotation 2020-07-12 092742

@onomatopellan
Copy link

Some service is using both ports. To know the service on the same Resource Monitor go to CPU tab -> Services, order by PID and look for PID 4248.

@therealkenc
Copy link
Collaborator

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

@peterjuras
Copy link
Author

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.

@lgyaxx
Copy link

lgyaxx commented Aug 3, 2020

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

Thanks a million for this!

@adolgoff
Copy link

adolgoff commented Nov 2, 2020

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.

@damienallen
Copy link

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.

Restarting WSL was also the solution that I needed! The PS command is still very useful for troubleshooting this though!

@larizzatg
Copy link

wsl --shutdown

This solved my issue, thank you

@micskeil
Copy link

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

@joshjm
Copy link

joshjm commented Sep 20, 2021

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

@tekkies
Copy link

tekkies commented May 12, 2022

This worked for me
https://superuser.com/a/1671709/28261

@RunhangShu
Copy link

In my case, my port is not allowed. After I add a new rule allowing the port in window firewall, it works. https://pureinfotech.com/open-port-firewall-windows-10/

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

No branches or pull requests