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

Huge amount of ports are being reserved #5306

Closed
Humberd opened this issue May 31, 2020 · 11 comments
Closed

Huge amount of ports are being reserved #5306

Humberd opened this issue May 31, 2020 · 11 comments

Comments

@Humberd
Copy link

Humberd commented May 31, 2020

After updating to WSL2 there is a huge amount of ports reserved.

Running this command: netsh int ipv4 show excludedportrange protocol=tcp i can tell that most ports from 4294 to 9783 are reserved.

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
      4294        4393
      4394        4493
      4494        4593
      4594        4693
      4694        4793
      4794        4893
      4894        4993
      5141        5240
      5241        5340
      5341        5440
      5441        5540
      5541        5640
      5641        5740
      5741        5840
      6041        6140
      6141        6240
      6241        6340
      6341        6440
      6441        6540
      6541        6640
      6641        6740
      7044        7143
      7144        7243
      7244        7343
      7344        7443
      7444        7543
      7544        7643
      7644        7743
      7949        8048
      8049        8148
      8149        8248
      8249        8348
      8984        9083
      9084        9183
      9184        9283
      9284        9383
      9384        9483
      9484        9583
      9584        9683
      9684        9783
     50000       50059     *
     54235       54235
     54236       54236

This is very troublesome, because I can't event start docker container on a port, because it throws

ERROR: for db  Cannot start service db: Ports are not available: listen tcp 0.0.0.0:5432: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

@edit

Please fill out the below information:

  • Your Windows build number: (Type ver at a Windows Command Prompt)

Microsoft Windows [Version 10.0.19041.264]

  • What you're doing and what's happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)

Described at the beginning of the issue

  • What's wrong / what should be happening instead:

Described at the beginning of the issue

  • Strace of the failing command, if applicable: (If some_command is failing, then run strace -o some_command.strace -f some_command some_args, and link the contents of some_command.strace in a gist here).

Not running a command. Proccesses don't start because ports are reserved

@Biswa96
Copy link

Biswa96 commented May 31, 2020

Are you sure those are assigned for WSL? Can you check the output from TcpView tool as administrator? Also please fill up all the fields of the issue template, its useful to fix issues.

@Humberd
Copy link
Author

Humberd commented May 31, 2020

@Biswa96 The ports are reserved, but not process uses them.

  1. First I completely uninstalled Hyper-V, Docker for Windows and WSL.
  2. After restart the ports were no longer reserved.
  3. Then I installed WSL.
  4. There were more ports reserved than before, but they were from 10000+, so I didn't care.
  5. Then I installed update to WSL2 from https://docs.microsoft.com/pl-pl/windows/wsl/wsl2-kernel
  6. BAM. The ports from range 5000 to 9500 are now reserved.

I have installed Windows update to 2004 2 days ago, but this problem arose today.

@onomatopellan
Copy link

onomatopellan commented May 31, 2020

This is my output of netsh int ipv4 show excludedportrange protocol=tcp

Start Port    End Port
----------          --------
      2869        2869
      5357        5357
     10243       10243
     49338       49437
     50000       50059     *
     51421       51520
     54742       54841
     54842       54941

I have Hyper-V and WSL2 enabled with a running Docker container and working without issue.

Do you have anything different from a new install? Additional Av/Firewall, DNS server, VPN... it looks like something is being blocked and insists in reserving ports.

Edit: Found user with same problem and a workaround
https://stackoverflow.com/a/62061654/6682245

@Humberd
Copy link
Author

Humberd commented May 31, 2020

I have absolutely no idea why I had this problem. I just reinstalled Windows and now all works fine

@onomatopellan
Copy link

A faulty Windows upgrade is the reason for the problems with reserved tcp ports.
See docker/for-win#3171 (comment).
With this the problem should be fixed:
netsh int ipv4 set dynamic tcp start=49152 num=16384

That would explain why a clean install fixes these type of problems.

@nij4t
Copy link

nij4t commented May 21, 2021

If that happens again, try this:

net stop winnat
net start winnat

@therealkenc
Copy link
Collaborator

/dupe #5514

@ghost
Copy link

ghost commented May 21, 2021

Hi! We've identified this issue as a duplicate of another one that already exists in this repository. This specific instance is being closed in favor of tracking the concern over on the referenced thread.

Thanks for your report!

@DanteMarshal
Copy link

DanteMarshal commented Sep 18, 2021

A faulty Windows upgrade is the reason for the problems with reserved tcp ports.
See docker/for-win#3171 (comment).
With this the problem should be fixed:
netsh int ipv4 set dynamic tcp start=49152 num=16384

That would explain why a clean install fixes these type of problems.

I had the same problem and my 1080 port was reserved so I couldn't run my local socks5 service.
This fixed my problem, Thank you.
You can run netsh int ipv4 show dynamic protocol=tcp before to make sure that is your case (that the port you have problems with in this range)

@elianbarci
Copy link

elianbarci commented Jun 13, 2022

In my case I solve this issue knowing which port my application needs (25340) and knowing what ranges are reserved by

netsh int ipv4 show excludedportrange protocol=tcp

which gives me this output:


  1025        1124
  1125        1224
  1225        1324
  1325        1424
  1425        1524
  1525        1624
  5357        5357
  5700        5700
  8884        8884
 24266       24365
 24466       24565
 24566       24665
 24666       24765
 24902       25001
 25002       25101
 25102       25201
 25313       25412
 25513       25612
 25613       25712
 25713       25812
 25913       26012
 26013       26112
 26113       26212
 50000       50059`

As you can see, this command tells me that from 25313 to 25412 those ports are reserved, so I simply change the port of my app and now all is working fine.

@EntityinArray
Copy link

If that happens again, try this:

net stop winnat
net start winnat

how about fix?

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

No branches or pull requests

8 participants