This topic describes the cause of and solution to the issue that the SSH logon or data transfer is slow on a Linux Elastic Compute Service (ECS) instance.
Problem description
When you use SSH to log on or transfer data to a Linux ECS instance over the Internet or internal network, the logon or data transfer is slow.
Cause
The preceding issue may occur because the UseDNS feature is enabled in the SSH configuration file of the Linux ECS instance, which is the /etc/ssh/sshd_config
file.
UseDNS is a security enhancement feature of the SSH service. By default, the UseDNS feature is disabled. After the UseDNS feature is enabled, the server performs a Domain Name System (DNS) pointer (PTR) record lookup to obtain the hostname of a client based on the IP address of the client, performs a DNS A record lookup to obtain an IP address based on the obtained hostname of the client, and then compares the obtained IP address against the IP address of the client. This helps prevent client spoofing.
In most cases, clients use dynamic IP addresses and do not have DNS PTR records. After the UseDNS feature is enabled, information cannot be compared, and the operation latency is increased due to DNS lookups. As a result, the connections from clients slow down.
Solution
Log on to the Linux ECS instance.
For more information, see Methods for connecting to an ECS instance.
Run the following command to view the SSH configuration file:
cat /etc/ssh/sshd_config
The following command output indicates that the UseDNS feature is enabled.
UseDNS yes
Modify the SSH configuration file.
Run the following command to open the SSH configuration file:
vi /etc/ssh/sshd_config
Add a number sign (
#
) before the following line to comment out the line or change the value of the UseDNS parameter fromyes
tono
to disable the UseDNS feature.# UseDNS no
Press the Esc key, enter
:wq
, and then press the Enter key to save and close the configuration file.Run the following command to restart the SSH service:
systemctl restart sshd.service