Steps to fix the error "telnet: connection refused by remote host"



Telnet errors are sometimes difficult to figure out.
One of such error is telnet: connection refused by remote host.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to fix Telnet related errors.
In this context, we shall look into the main causes of this error and how to get rid of it.

Causes and Fixes for error "telnet connection refused by remote host"?

Below are the main causes  for the error "telnet connection refused by remote host" and how to tackle it.
1. Telnet service not running
One of the most likely reasons is that the telnet service isn’t installed on the machine the user is trying to connect.
"Telnetd" is the daemon that supports Telnet protocol. So, for the telnet communication to happen smoothly, telnet service must be installed at the destination. Otherwise, there’s no daemon to answer the telnet connection from source and results in this error.
And, customers see the below error when they use telnet to connect to localhost or any other server.

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

Solution
In such cases, check if Telnet is installed on the machine they are trying to connect. Otherwise, it must first be installed. For example, on Linux Ubuntu servers, we install telnet tool using the below command;

apt-get install telnetd

Additionally, ensure that this service is started and running fine in the server. We usually start the telnet service using the below command;

/etc/init.d/inetd restart

Moreover, we ensure that the machine that we are connecting to does not block the standard telnet port 23. If so, we’ll open the port in the server firewall. For example, we allow the telnet port in UFW using the following command;

ufw allow 23/tcp

However, Telnet is highly insecure as the communication is not encrypted. In other words, your passwords and all other data is transferred as plain text which is insecure. So, our Support Experts always recommend customers use Secure Shell(SSH) instead of telnet. And, only use telnet unless it’s absolutely necessary.

2. Telnet disabled in configuration file

Another common possibility for the error telnet: connection refused by remote host is telnet service disabled in it's configuration file.
"Xinetd" service controls telnet in Linux. There is a parameter disable in xinetd configuration file "/etc/xinetd.d/telnet". This decides whether telnet service should be disabled in the server or not. We’ve seen instances where users forget to enable this parameter which can cause problems.

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

Solution?
Ensure that the telnet service is enabled on the destination server by changing the parameter disable=no. Most importantly, we take a backup of this file before making changes. Also, we make sure to restart the xinetd service to reflect these changes.

[Need urgent help in installing telnet service on your server? We can help you here.]


3. Firewall restrictions
Similarly, this error may occur when the firewall in between is rejecting the connections.
For example, customers see the below error when firewall is restricting the connections;

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

This error means that firewall is blocking connections to the specified port on the remote host. The firewall can be at the remote host or at the intermediate level.

Solution?
In such cases, our Support Engineers get the traceroute results from the client side to the destination end. This gives us an idea where the connection is getting interrupted.
If the connection is interrupted at the remote host, then we make sure that the required port is opened in the server firewall. Moreover, we ensure that the customer’s IP address isn’t blocked at the remote host. Alternatively, if the connection drops at the intermediate level, then most probably the issue lies at the ISP end. In such cases, customers need to contact the ISP end to fix the problem.

4. Service not running
Another possible reason for this error is that there is no service listening on the connected port.
For example, server owners usually set the HTTP port to 80. Consider customers trying to connect to port 80 using telnet, but the HTTP service isn't running on the server. So, users receive the below error;

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

Solution?
In such cases, our Support Engineers first verify whether the service is enabled and running on the server. For example, on Linux servers, we check the status of http service as below;

ps aux | grep http

Further, we verify the port that this service is listening. For example, we use the netstat command to verify the port on which the http service listens. In addition to that, this command also shows which IP address it’s actually bound to.

netstat -lnpt | grep :80

So, a wrong port or IP address is used then it is important to update them to use the correct details for connecting.

[Need an Expert to fix Server errors? We are available to help you today.]


Conclusion

This article will guide you on the processes to fix telnet: connection refused by remote host which generally occurs due to firewall restrictions, disabled telnet service, and so on.


Related Post


Focus on your business, not your servers.

Click Here to Learn More






Keep In Touch

We hope to hear from you.

Accept File Type: jpg,jpeg,png,txt,pdf,doc,docx