Reserve a TCP port in Windows

后端 未结 5 1723
小鲜肉
小鲜肉 2021-02-01 23:14

I\'d like to reserve a TCP port, to be bound by a service later, so that Windows doesn\'t inadvertently use the same number when assigning random port numbers. I know this is po

5条回答
  •  春和景丽
    2021-02-01 23:44

    As mentioned by @vahapt you can modify the dynamic port range using netsh.

    However, a better solution may be to use netsh to reserve the ports required by your application, leaving alone the default range of dynamic ports.

    To do so:

    1. On Server 2008/2008 R2, install this Microsoft hotfix. This is not required on Server 2012 or later.
    2. Stop any processes using the ports to be reserved. If a process is using a port included in the range of ports to be reserved, NETSH will return the following error and the reservation will fail:

      The process cannot access the file because it is being used by another process.

    3. Use the following NETSH command to reserve the ports:

      netsh int Add excludedportrange [protocol=]tcp|udp [startport=] [numberofports=] [[store=]active|persistent]

      For example, to reserve ports 55368-55372 for UDPv6, use the command:

      netsh int ipv6 add excludedportrange protocol=udp startport=55368 numberofports=5

    Notes:

    • By default port reservations are persistent across reboots
    • Ports may be reserved for either version 4 or 6 of a protocol, but not both (i.e. you cannot reserve port 60000 for both TCPv4 and TCPv6)

    See https://support.microsoft.com/en-us/kb/929851 for more information, including how to view or delete existing port reservations.

提交回复
热议问题