doc-exports/docs/ecs/umn/en-us_topic_0244854543.html
guoyanyan a810508850 ecs_umn_1109
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: guoyanyan <guoyanyan3@huawei.com>
Co-committed-by: guoyanyan <guoyanyan3@huawei.com>
2022-12-05 15:44:44 +00:00

15 KiB

How Can I Change a Remote Login Port?

Scenarios

This section describes how to change a port for remote logins.

Windows

The following procedure uses an ECS running Windows Server 2012 as an example. The default login port of a Windows ECS is 3389. To change it to port 2020, for example, do as follows:

  1. In the Run dialog box, enter regedit to access the registry editor.
  2. In Registry Editor, choose HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > Control > Terminal Server > Wds > rdpwd > Tds > tcp and double-click PortNumber.
    1. In the dialog box that is displayed, set Base to Decimal.
    2. Change the value in Value data to the new port number, which is 2020 in this example.
      Figure 1 Changing the port number to 2020
  3. In Registry Editor, choose HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > Control > Terminal Server > WinStations > RDP-Tcp and double-click PortNumber.
    1. In the dialog box that is displayed, set Base to Decimal.
    2. Change the value in Value data to the new port number, which is 2020 in this example.
      Figure 2 Changing the port number to 2020
  4. (Skip this step if the firewall is disabled.) Modify the inbound rules of the firewall.

    Choose Control Panel > Windows Firewall > Advanced Settings > Inbound Rules > New Rule.

    • Rule Type: Port
    • Protocol in Protocol and Ports: TCP
    • Port in Protocol and Ports: Specific local ports, 2020 in this example
    • Action: Allow the connection
    • Profile: Default settings
    • Name: RDP-2020

    After the configuration, refresh the page to view the new rule.

  5. Modify the security group rule.

    Add an inbound rule in which Protocol is set to TCP and Port Range is set to 2020.

    For details, see "Adding a Security Group Rule" in the Virtual Private Cloud User Guide.

    Use port 2020 to remotely log in to the ECS.

  6. Open the Windows search box, enter services, and select Services.
    Figure 3 Selecting Services
  7. In the Services window, restart Remote Desktop Services or the ECS.
  8. Use "IP address:Port" to remotely access the ECS.

Linux

The following procedure uses an ECS running CentOS 7.3 as an example. The default login port of a Linux ECS is 22. To change it to port 2020, for example, do as follows:

  1. Run the following command to edit the sshd configuration file:

    vi /etc/ssh/sshd_config

  2. Delete the comment tag (#) from the #port 22 line and change 22 to 2020.
    Figure 4 Changing the port number to 2020
  3. Press Esc to exit Insert mode and enter :wq! to save the settings and exit.
  4. Run either of the following commands to restart sshd:

    service sshd restart

    Or

    systemctl restart sshd

  5. Skip this step if the firewall is disabled. Configure the firewall.

    The firewall varies depending on the CentOS version. CentOS 7 uses firewalld, and CentOS 6 uses iptables. The following operations use CentOS 7 as an example.

    Run the firewall-cmd --state command to check the firewall status.

    • (Recommended) Method 1: Add information about a new port to firewalld.
      1. Run the following commands to add a rule for port 2020:

        firewall-cmd --zone=public --add-port=2020/tcp --permanent

        firewall-cmd --reload

      2. View the added port. The TCP connection of port 2020 will have been added.

        firewall-cmd --list-all

      3. Restart firewalld.

        systemctl restart firewalld.service

    • Method 2: Disable the firewall and the function of automatically enabling the firewall upon ECS startup.

      systemctl stop firewalld

      systemctl disable firewalld

  6. Modify the security group rule.

    Add an inbound rule in which Protocol is set to TCP and Port Range is set to 2020.

    For details, see "Adding a Security Group Rule" in the Virtual Private Cloud User Guide.

    Use port 2020 to remotely log in to the ECS.

  7. Run the following command to check whether the port is open:

    telnet EIP Port

    For example: telnet xx.xx.xx.xx 2020