XPost: alt.comp.os.windows-11, comp.mobile.android
Warning: If you enable Hyper-V (e.g., WSL, Docker, VMs, etc.) on Windows,
and if you ever want to assign an outgoing port to any process (e.g.,
stunnel, adb, etc.), then you will be a very unhappy person (for years!) if
you don't heed this warning outlined below.
A. Things will work just fine when you set it up
B. But, randomly, after a boot (maybe months later) things fail
C. And yet, another reboot (or two) instantly fixes it again
Over and over... for years...
Hence, this would be the WRONG way to do things (which I apparently did).
a. You use stunnel or adb (or anything else that needs outgoing ports)
b. If you enabled Hyper-V - you will be very sorry with what happens
c. Because available outgoing ports will be randomly yanked from you
It's completely random (AFAICT).
So if it worked today, it could just as well fail next week.
With zero debugging information (other than port binding failed).
Why?
1. Apparently Hyper-V, is enabled by WSL, Docker, VMs, etc.
PS> Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
2. Hyper-V tells WinNAT to exclude random blocks of ports
3. This happens for IPv4, IPv6, UDP & TCP but we'll focus on TCP only
4. In my case, 13 random blocks of 100 contiguous ports were reserved
5. Each reboot would randomly select another set of 13 random blocks
6. So, for example, if ADB is using port 55555, then you're fine if
the 1300 random blocks don't include 55555 but you're screwed if they do
7. ADB will fail but all ADB knows is that a permission was denied
C:\> adb devices
* daemon not running; starting now at tcp:55555
could not read ok from ADB Server
* failed to start daemon
adb.exe: failed to check server version: cannot connect to daemon
8. There is no debugging ADB can give as it only knows permission denied
9. Even netstat can't help you, nor resmon, nor promon, nor powershell
C:\> netstat -ano | findstr :54555 (returns nothing!)
10. You won't be able to even manually bind to those 1300 random ports
C:\> ncat -l -p 55555 (ADB will fail with "permission denied")
11. Yet, nothing is using those 1300 ports so you can not work backward
C:\> resmon > Network > Listening Ports > Port = 54321 > PID
C:\> procexp.exe > Find > Find Handle or DLL > 54321 > Search
C:\> procmon.exe > Filter (timing is crucial)
12. The only way you know the ports are excluded is to run this command.
C:\> netsh interface ipv4 show excludedportrange protocol=tcp
What's the *PROPER* way to let adb use port 55555 (which is its default)?
1. The proper way is to know ahead of time you need to reserve the port!
C:\> netsh int ipv4 add excludedportrange protocol=tcp startport=55555 numberofports=1
2. Once you reserve the port, then ADB will have no problem using it
3. Better yet, when Hyper-V tells WinNAT to exclude 1300 random ports,
winnat will skip any port you've previously excluded, so you're fine
Notice that the *proper* way to use some tools which need an outgoing port
is to exclude that port first, and then use the tool that needs that port.
In the case of ADB, the port is the default (AFAIK), where I wouldn't know
how to change the default port ADB uses to connect to Android over USB.
However, in the case of Stunnel, you will want most likely to reserve a
block of ports since you can easily set up more than one nntp server.
To reserve a block of 100 ports just for your personal use, use this:
C:\> netsh int ipv4 add excludedportrange protocol=tcp startport=55500 numberofports=101
Now you have, forever, your own block of outgoing ports from 55500
to 55600 that you can use for any program that needs a port set.
I never took a class in networking so I don't really know why you
have to do this - but all I know it not knowing this cost me zillions
of hours over the years of wasted debugging that knowing what is in this
one post would have saved me (and which is why I'm posting this for you).
Let me know if you have any questions. More details are in this thread:
*Port Permission Denied finally resolved after years of debugging*
<
https://www.novabbs.com/computers/article-flat.php?id=87044&group=alt.comp.os.windows-10#87044>
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)