How to solve “telnet: connection refused by remote host” error?

admin

The following sections detail the most common causes of the error “telnet: connection refused by remote host”.

1. Telnet service not running

One of the most likely causes is that the user’s machine does not have the telnet service installed.

Telnet is a daemon that enables the Telnet protocol to lớn be used. Thus, for telnet communication to lớn lập cập smoothly, the destination must have the telnet service installed. Otherwise, there is no daemon to lớn respond to lớn the source telnet connection, resulting in this error.

Additionally, customers receive the following error when attempting to lớn connect to lớn localhost or any other server via telnet.

telnet localhost 1181
Trying 127.0.0.1...
telnet: Unable to lớn connect to lớn remote host: Connection refused

Check if Telnet is installed on the machine in which they are attempting to lớn connect. Otherwise, it should be installed first. On Linux Ubuntu servers, you can install the telnet tool with the command below.

apt-get install telnetd

Verify that the service has started and running normally on the server. Typically, you can start the telnet service with the following command.


/etc/init.d/inetd restart

Check to lớn make certain that the machine to lớn which you are connecting does not block the standard telnet port 23. If that is the case, you should open the port on the server’s firewall. For example, the following command allows the telnet port in UFW.

ufw allow 23/tcp

Telnet, on the other hand is extremely insecure because the communication is not encrypted. In other words, your passwords and other sensitive information are transmitted in plain text, which is in an insecure format. As a result, our Support Specialists always recommend that customers use Secure Shell (SSH) rather kêu ca Telnet. Additionally, avoid using telnet unless necessary.

2. Telnet is deactivated in configuration file

Another common cause of the error telnet: connection refused by the remote host is a configuration tệp tin that has the telnet service disabled.

In Linux, the xinetd service manages telnet. In the xinetd configuration tệp tin “/etc/xinetd.d/telnet“, there is a parameter disable. This specifies whether the server’s telnet services should be disabled or not. If you forget to lớn enable this parameter, it results in issues.

service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = yes
}

How to lớn fix it? 

Ensure that the destination server’s telnet service is enabled by changing the disable=no parameter. Most importantly, before making changes to lớn this tệp tin, create a backup. Moreover, make sure that the xinetd service is restarted to lớn reflect these changes.

3. Firewall restrictions

This occurs when the firewall in between is rejecting the connections.

For example, when a firewall is restricting connections, customers see the following error.

$ telnet 52.83.122.133 200
Trying 52.83.122.133...
telnet: Unable to lớn connect to lớn remote host: Connection refused

This indicates that the firewall is preventing connections to lớn the remote host’s specified port.

How to lớn fix it?

If the remote host’s connection is lost, ensure that the required port is opened in the server firewall. Make certain that the customer’s IP address is not blocked by the remote host. Alternatively, if the connection fails at the intermediate level, the issue is almost certainly with the ISP. In these cases, you must liên hệ their ISP to lớn resolve the issue.

4) Service not running

Another possible cause of this error is that the connected port does not have any service listening.

For example, server administrators assign HTTP port 80 to lớn their servers. While attempting to lớn connect to lớn port 80 via telnet, but the server’s HTTP service is not running. As a result, the below error is displayed to lớn users.

$ telnet xx.xx.xxx.xxx 80
Trying xx.xx.xxx.xxx...
telnet: Unable to lớn connect to lớn remote host: Connection refused
Telnet

How to lớn fix it?

First, verify that the service is enabled and running. On Linux servers, kiểm tra the status of the http service as follows.

ps aux | grep http

Verify the port on which this service is listening. Use the netstat command to lớn determine which port the http service listens on. Additionally, this command displays the IP address to lớn which it is actually bound.

netstat -lnpt | grep :80	

Do you require the assistance of a technical expert to lớn resolve the issue? Contact us.