This topic describes how to modify the default port used by an Elastic Compute Service
(ECS) instance to accept connections.
Modify the default port used by a Windows instance to accept connections
This section describes how to modify the default port used by a Windows instance to
accept connections. In this example, Windows Server 2012 is used.
- Connect and log on to the Windows instance.
- Modify the value of the PortNumber registry subkey.
- Press Win+R to open the Run command window.
- Enter regedit.exe and press the Enter key to open the registry editor.
- In the left-side navigation pane, choose .
- Find and right-click PortNumber in the right list, and select Modify....
- In the Edit DWORD (32-bit) Value dialog box, enter a new port number in the Value data field. In this example, enter 3399. Select Decimal in the Base section and click OK.
- In the left-side navigation pane, choose .
- Find and right-click PortNumber in the right list, and select Modify....
- In the Edit DWORD (32-bit) Value dialog box, enter a new port number in the Value data field. In this example, enter 3399. Select Decimal in the Base section and click OK.
- Restart the instance in the ECS console.
- Add security group rules to the security group of the instance to allow connections
to the new port.
- Connect to the instance. In the Remote Desktop Connection dialog box, enter <IP address
of the instance>:<New port number> in the Computer field and click Connect to connect
to the instance.

Note Mac Remote Desktop Connection can only be used to connect to the instance over the
default port 3389.
Modify the default port used by a Linux instance to accept connections
This section describes how to modify the default port used by a Linux instance to
accept connections. In the example, CentOS 6.8 and CentOS 7.7 are used.
- Connect and log on to the Linux instance.
- Run the following command to back up the sshd configuration file:
cp /etc/ssh/sshd_config /etc/ssh/sshd_config_bak
- Modify the port number of sshd.
- Run the following command to edit the sshd_config configuration file:
- Press the
I
key to enter the edit mode.
- Add a new port to accept connections.
In this example, add port 1022. Enter
Port 1022
under
Port 22
.

- Press the
Esc
key, enter :wq, and then press the Enter key to save and close the file.
- Run one of the following commands to restart sshd. After sshd is restarted, you can
log on to the Linux instance by using SSH port 1022.
- If the Linux instance runs CentOS 7 or later, or Alibaba Cloud Linux 2, run the following
command:
systemctl restart sshd
- If the Linux instance runs CentOS 6, run the following command:
/etc/init.d/sshd restart
- Add security group rules to the security group of the instance to allow traffic over
TCP port 1022.
- Use an SSH client to connect to the instance to check whether traffic over the new
port is allowed.
Enter the new port number in the
Port field. In this example, enter 1022.

Note
After the port number is modified, you cannot use the default port 22 to connect to
the instance.