Adjust TCP Dynamic Port Timeout in Regedit

When a Windows system experiences heavy network traffic, outbound connections can rapidly consume all available dynamic ports, leading to port exhaustion. By default, closed TCP connections remain in a TIME_WAIT state for four minutes (240 seconds) to ensure all packets are received before the port is recycled. This guide explains how to adjust the system-wide dynamic port timeout using the Windows Registry Editor (regedit) to reduce the TIME_WAIT duration and free up ports much faster.

Steps to Modify the TCP Dynamic Port Timeout

  1. Open Registry Editor
    • Press Win + R on your keyboard to open the Run dialog.
    • Type regedit and press Enter (or click OK).
    • Click Yes if prompted by User Account Control (UAC).
  2. Navigate to the TCP/IP Parameters Key
    • In the Registry Editor address bar, paste the following path and press Enter:

      HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
  3. Create or Modify TcpTimedWaitDelay
    • Check the right-hand pane for a value named TcpTimedWaitDelay.
    • If it does not exist:
      • Right-click an empty space in the right pane.
      • Select New > DWORD (32-bit) Value.
      • Name the value TcpTimedWaitDelay.
    • Double-click TcpTimedWaitDelay to edit it.
  4. Set the Timeout Value
    • Under Base, select Decimal.
    • In the Value data field, enter the desired timeout duration in seconds:
      • Minimum recommended: 30 (30 seconds)
      • Default: 240 (4 minutes)
      • Valid range: 30 to 300
    • Click OK to save the changes.
  5. Restart the System
    • Close the Registry Editor.
    • Restart your computer or server for the registry changes to take effect system-wide.

Optional: Increase Dynamic Port Range (MaxUserPort)

If shortening the timeout delay does not fully resolve port exhaustion, you can increase the total number of user-accessible dynamic ports in the same registry location:

  1. In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters, right-click and choose New > DWORD (32-bit) Value.
  2. Name it MaxUserPort.
  3. Double-click it, set the Base to Decimal, and enter a value between 5000 and 65534 (e.g., 65534 to allocate the maximum allowable ports).
  4. Click OK and restart your system.