This topic describes the following issue, the cause of the issue, and the solution to the issue: A Windows Elastic Compute Service (ECS) instance cannot access external networks when a large number of connections stay in the TIME_WAIT state on the instance.
Problem description
An external network can be pinged from a Windows instance, but the external network cannot be accessed by using a browser from the instance, excessive time is required to load external webpages, or a network connectivity exception occurs in applications that are hosted on the instance. After you run the netstat -an |find "TIME_WAIT" /c command in Command Prompt on the instance, the command output indicates that a large number of TCP connections are in the TIME_WAIT state. The following figure shows a sample command output.
Cause
In Windows Server 2008 and later, 16,384 dynamic ports (from port 49152 to port 65535) are provided by default. By default, a TCP connection stays in the TIME_WAIT state for 4 minutes before the connection is closed. If a large number of TCP connections are active on an instance, many connections may simultaneously stay in the TIME_WAIT state and continue to consume a large number of ports after these connections end. As a result, new connections or applications have no ports to consume and exceptions occur.
Solution
This section describes how to resolve the issue. In the example, an instance that runs Windows Server 2012 R2 is used. The operations that you must perform may vary based on the operating system of your instance.
Connect to the Windows instance by using Virtual Network Computing (VNC).
For more information, see Connect to a Windows instance by using a password.
Start Command Prompt.
In the lower-left corner of the desktop, click the
icon and then click the
icon. In the search box, enter
cmd.
Click Command Prompt.
Open the Command Prompt window.

Run the following command to view the configurations of dynamic ports:
netsh int ipv4 show dynamicport tcpThe following figure shows a sample command output, which indicates that 16,384 dynamic ports (from port 49152 to port 65535) are provided.

Run the following command to extend the dynamic port range:
netsh int ipv4 set dynamicport tcp start=1025 num=60000NoteThe
startparameter specifies the start port of the dynamic port range. Thenumparameter specifies the number of dynamic ports. You can configure the parameters based on your needs.The following figure shows a sample command output, which indicates that the number of dynamic ports is increased to 60,000 and the new dynamic port range starts at port 1025 and ends at port 61024.

Access the external network again or connect applications to the external network.
If the external network can be accessed or connected, the issue is resolved.
If the external network cannot be accessed or connected, change the value of the TcpTimedWaitDelay registry key to reduce the length of time that a TCP connection stays in the TIME_WAIT state before the connection is closed.
If the issue is not completely resolved after the dynamic port range is extended, you can reduce the value of the TcpTimedWaitDelay registry key to 30 seconds. The minimum value of the TcpTimedWaitDelay registry key is 30 seconds.
ImportantTo prevent operating system issues or data loss caused by accidental operations on the registry, create snapshots for the system disk and data disks of the instance before you modify the registry. After the registry is modified, you must restart the instance for the modifications to take effect.
For information about how to create a snapshot, see Create a snapshot for a disk.
For information about how to restart an instance, see Restart instances.
Start Registry Editor.
In the lower-left corner of the desktop, click the
icon and then click the
icon. In the search box, enter
regedit.
Click regedit.
Open the Registry Editor window.

Navigate to the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameterspath and set theTcpTimedWaitDelayregistry key to the decimal value30.If the
TcpTimedWaitDelaykey does not exist, perform the following operations to create the key and change its value:In the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameterspath in the Registry Editor window, right-click a blank area in the right-side pane and choose New > DWORD (32-bit) Value.
Enter
TcpTimedWaitDelayand press theEnterkey.Right-click
TcpTimedWaitDelayand select Modify.
In the dialog box that appears, select Decimal and change the value in the Value data field to
30.
Click OK.