When attempting to make a connection using Telnet, if error message Telnet: unable to connect to remote host: connection refused appears, follow these troubleshooting directions. This tutorial was written assumeing you are using Linux. Try to make the telnet connection without using a specific port. For example, if error Telnet: unable to connect to remote host: connection refused appears when making a telnet connection on port 25 (stmp email) using command telnet localhost 25, drop the port number and just enter the telnet command without a port.
When using the telnet command without a port number, if the connection is successful, this means there is some issue with the service associated with the port being used. As an example, if error Telnet: unable to connect to remote host: connection refused appears when attempting to connect to port 25 (smtp), this implies there is some issue with the smtp service. This is not a problem with telnet. There can be quite a few things wrong with the service. As an example, the service might not be running. On the server running the service, check the status of the service.
service postfix status
In this example, if the output of the service postfix status command is postfix is not running, we have identified the cause of the error. In this example, error Telnet: unable to connect to remote host: connection refused when using the telnet localhost 25 command because postfix is not running.
Another example is that the service may not be properly configured. As an example, in the tutorial on how to install and configure Postfix on Linux, there are instructions list inet_interfaces = all in the Postifx main configuration file. If we did not follow this tutorial, and the Postifx main configuration file has inet_interfaces = localhost, this would cause error Telnet: unable to connect to remote host: connection refused to appear when attempting to make a telnet connection on port 25 to the server.
These are just two example scenarios. Given the number of services and possible issues with each service, this is just touching the surface of the number of issues that can cause this error. The point here is to determine if the issue is with Telnet or with another service, so you can properly focus your attention on the right software that needs to be debugged.