Skip to content

Instantly share code, notes, and snippets.

@elonderin
Forked from strayge/reverved_ports_hyperv.md
Created February 13, 2023 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elonderin/c76793b1a7d305b70d095b5fd7435e7d to your computer and use it in GitHub Desktop.
Save elonderin/c76793b1a7d305b70d095b5fd7435e7d to your computer and use it in GitHub Desktop.
windows 10, port reserved for HyperV

Error

docker windows bind: An attempt was made to access a socket in a way forbidden by its access permissions.

show reserved pool

netsh int ipv4 show excludedportrange protocol=tcp

undocumented key in registry

https://dandini.wordpress.com/2019/07/15/administered-port-exclusions-blocking-high-ports/

rem Modify Dynamic Port Range for Development Users
dism /online /get-features | find /i "Microsoft-Hyper-V" && (
rem Modify Dynamic Port Range
start /wait "" netsh int ipv4 set dynamicport tcp start=20000 num=16384
start /wait "" netsh int ipv4 set dynamicport udp start=20000 num=16384
rem Add Registry Key
start /wait "" reg add HKLM\SYSTEM\CurrentControlSet\Services\hns\State /v EnableExcludedPortRange /d 0 /f
goto :eof
)
rem Set range to default
start /wait "" netsh int ipv4 set dynamicport tcp start=49152 num=16384
start /wait "" netsh int ipv4 set dynamicport udp start=49152 num=16384
rem Remove Registry Key
start /wait "" reg delete HKLM\SYSTEM\CurrentControlSet\Services\hns\State /v EnableExcludedPortRange /f

another workaround

docker/for-win#3171 (comment)

Disable hyper-v (which will required a couple of restarts) dism.exe /Online /Disable-Feature:Microsoft-Hyper-V

When you finish all the required restarts, reserve the port you want so hyper-v doesn't reserve it back netsh int ipv4 add excludedportrange protocol=tcp startport=50051 numberofports=1

Re-Enable hyper-V (which will require a couple of restart) dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All

when your system is back, you will be able to bind to that port successfully.

@elonderin
Copy link
Author

elonderin commented Feb 13, 2023

i have suffered from this issue in the past but it has been quite for a while.
Anyhow, i just tried to execute the commands in an admin cmd:

start /wait "" netsh int ipv4 set dynamicport tcp start=20000 num=16384
start /wait "" netsh int ipv4 set dynamicport udp start=20000 num=16384
rem Add Registry Key
start /wait "" reg add HKLM\SYSTEM\CurrentControlSet\Services\hns\State /v EnableExcludedPortRange /d 0 /f
goto :eof

this seems to have no effect w/o a restart:

> netsh interface ipv4 show excludedportrange protocol=tcp

Protocol tcp Port Exclusion Ranges

Start Port    End Port      
----------    --------      
      5357        5357      
      9009        9009      
     49195       49294      
     50000       50059     *
     58928       59027      
     59228       59327      
     59438       59537      
     59738       59837      
     60200       60299      
     60300       60399      
     65385       65484      

* - Administered port exclusions.

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