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

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 the daemon that enables the Telnet protocol to be used. Thus, for telnet communication to run smoothly, the destination must have the telnet service installed. Otherwise, there is no daemon to respond to the source telnet connection, resulting in this error.

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

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

Check if Telnet is installed on the machine to which they are attempting to connect. Otherwise, it must 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 is 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 make certain that the machine to 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 an insecure format. As a result, our Support Specialists always recommend that customers use Secure Shell (SSH) rather than Telnet. Additionally, avoid using telnet unless necessary.

2. Telnet is deactivated in the configuration file

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

In Linux, the xinetd service manages telnet. In the xinetd configuration file “/etc/xinetd.d/telnet“, there is a parameter disable. This specifies whether the server’s telnet service should be disabled or not. If you forget to 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 fix it? 

Ensure that the destination server’s telnet service is enabled by changing the disable=no parameter. Most importantly, before making changes to this file, create a backup. Moreover, make sure that the xinetd service is restarted to 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 connect to remote host: Connection refused

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

How to 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 contact their ISP to 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 their servers. While attempting to connect to port 80 via telnet, but the server’s HTTP service is not running. As a result, the following error is displayed to users.

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

How to fix it?

First, verify that the service is enabled and running. On Linux servers, check 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 determine which port the http service listens on. Additionally, this command displays the IP address to which it is actually bound.

netstat -lnpt | grep :80	

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

FREE SERVER AUDITING

Get Auditing Report of Your Server for FREE!!

Fix this issue for

$25/Hour

$6.25/Hour

Applicable only to the first hour.