Windows: stop setting MaxUserPort and delete any existing value

nmap_performance.reg no longer sets MaxUserPort=0xfffe. It now contains
"MaxUserPort"=- instead, which deletes the value unconditionally: any
existing MaxUserPort is removed whenever the file is applied, whoever
set it, not only when an earlier Nmap installer wrote it. This is the
only way to undo what earlier installers did on upgrade. As before, the
file is only applied when the user opts into the "Network Performance
Improvements" installer section, and the dynamic port range itself
changes after the next reboot because MaxUserPort is read at boot.

MaxUserPort raised the ephemeral port limit on Windows 2000/XP/2003,
whose default dynamic port range was 1025-5000. Nmap dropped those
systems in 7.25BETA1, and since 7.92 the Windows binaries do not run on
Vista or earlier at all. On Windows Vista and later the default range is
already 49152-65535, and MaxUserPort instead widens it to 1024-65534.
That spreads every outgoing connection over the whole port space and
breaks software that needs a contiguous block of host ports: WSL2
mirrored networking fails with
CreateInstance/CreateVm/ConfigureNetworking/0x8007054f and falls back
to no networking (microsoft/WSL#13454, where several reporters traced
it to this installer option).

TcpTimedWaitDelay and StrictTimeWaitSeqCheck are unchanged. The install
guide now describes the deletion, the manual fix for users who do not
re-run the installer, and how to widen the ephemeral range with netsh
from a high starting port if a scan really needs more than 16384 ports.

Verified on Windows 11: applying the file with "regedt32 /S" deletes
MaxUserPort and sets the other two values. The installer itself was not
tested end to end.

Refs: GH#149
This commit is contained in:
結友 2026-09-11 10:09:31 +09:00
parent 8b515f26b8
commit 168eb1a349
No known key found for this signature in database
GPG key ID: A636CEF07950C391
3 changed files with 45 additions and 8 deletions

View file

@ -4,6 +4,17 @@ o [GH#3565][GH#3573] Fixed an issue with addrset: When a CIDR spec was added
after a narrower one, its prefix exactly the common prefix of the two, the
addrset trie did not cover the whole broader range. [Dennys Kaluzny Pereira]
o [Windows][GH#149] The "Network Performance Improvements" installer option
and nmap_performance.reg no longer set MaxUserPort, and instead delete any
existing MaxUserPort value, whoever set it, whenever that option is
selected. The value raised the ephemeral port limit on Windows 2000/XP/2003,
none of which Nmap has supported since 7.25BETA1. On Windows Vista and later
it instead widens the TCP dynamic port range from the default 49152-65535 to
1024-65534, which fragments the port space and breaks software that reserves
contiguous port ranges, such as WSL2 mirrored networking
(microsoft/WSL#13454). The TIME_WAIT reduction (TcpTimedWaitDelay,
StrictTimeWaitSeqCheck) is unchanged. [yuu61]
Nmap 7.993 [2026-10-23]
o [NSE][GH#3557] Fixed a regression which prevented most scripts in the version

View file

@ -757,23 +757,45 @@ in the <filename>nmap-<replaceable>version</replaceable></filename>
directory of the Windows binary zip file (for <ulink url="https://nmap.org/oem/">Nmap OEM</ulink> customers), and
<filename>nmap-<replaceable>version</replaceable>/mswin32</filename>
in the source tarball (where <replaceable>version</replaceable> is the
version number of the specific release). These changes increase
the number of ephemeral ports reserved for user applications (such as
Nmap) and reduce the time delay before a closed connection can
be reused. Most people simply check the box to apply these changes in the executable Nmap installer, but you can also apply them by double-clicking on
version number of the specific release). These changes reduce the
time delay before the port of a closed connection can be reused, so
that version detection and NSE scripts, which open many short-lived
connections, do not run out of ephemeral ports while old connections
linger in the <literal>TIME_WAIT</literal> state. Most people simply check the box to apply these changes in the executable Nmap installer, but you can also apply them by double-clicking on
<filename>nmap_performance.reg</filename>, or by running the command
<command>regedt32 nmap_performance.reg</command>. To make the changes by hand, add these three Registry DWORD values to
<command>regedt32 nmap_performance.reg</command>. To make the changes by hand, add these two Registry DWORD values to
<literal>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters</literal>:</para>
<variablelist>
<varlistentry><term>MaxUserPort</term>
<listitem><para>Set a large value such as 65534 (0x0000fffe). See <ulink url="https://support.microsoft.com/kb/196271">MS KB 196271</ulink>.</para></listitem></varlistentry>
<varlistentry><term>TCPTimedWaitDelay</term>
<listitem><para>Set the minimum value (0x0000001e). See <ulink url="https://support.microsoft.com/kb/149532">MS KB 149532</ulink>.</para></listitem></varlistentry>
<varlistentry><term>StrictTimeWaitSeqCheck</term>
<listitem><para>Set to 1 so TCPTimedWaitDelay is checked.</para></listitem></varlistentry>
</variablelist>
<note><para>Earlier Nmap releases also set
<literal>MaxUserPort</literal> to 65534. Applying
<filename>nmap_performance.reg</filename> now deletes that value
(the <literal>"MaxUserPort"=-</literal> line) whether Nmap or
something else set it; the dynamic range changes after the next
reboot. The value raised the ephemeral port limit on Windows
2000, XP and Server 2003, whose default dynamic range was only
1025&ndash;5000; Nmap has not supported those systems since 7.25BETA1.
Windows Vista and later already use 49152&ndash;65535 (16384 ports),
and on those systems <literal>MaxUserPort</literal> instead widens the
dynamic range to 1024&ndash;65534. That spreads outgoing connections
over the whole port space and breaks software which needs to reserve a
contiguous block of ports, such as WSL2 mirrored networking. If you do
not re-run the installer, delete <literal>MaxUserPort</literal> from the
Registry key above; the default range returns after the next reboot.
To restore it immediately as well, run
<command>netsh int ipv4 set dynamicport tcp start=49152 num=16384</command>
(and the same for <literal>ipv6</literal>) after deleting the value. If a very fast connect scan
really needs more than 16384 ephemeral ports, widen the range with
<command>netsh</command> from a high starting port instead, for example
<command>start=32768 num=32768</command>, which leaves the lower half of
the port space untouched.</para></note>
<note><para>I would like to thank Ryan Permeh<indexterm><primary>Permeh, Ryan</primary></indexterm> of eEye, Andy Lutomirski<indexterm><primary>Lutomirski, Andy</primary></indexterm>, and
Jens Vogt<indexterm><primary>Vogt, Jens</primary></indexterm> for their hard work on the Nmap Windows port. For many
years, Nmap was a Unix-only tool, and it would likely still be that

View file

@ -1,6 +1,10 @@
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]
"MaxUserPort"=dword:0000fffe
; Earlier Nmap releases set MaxUserPort=0xfffe. On Windows Vista and later
; that widens the TCP dynamic port range to 1024-65534 and breaks software
; that needs a contiguous block of ports (e.g. WSL2 mirrored networking).
; Remove it if an older installer left it behind.
"MaxUserPort"=-
"TcpTimedWaitDelay"=dword:0000001e
"StrictTimeWaitSeqCheck"=dword:00000001