Telnet, the protocol and the command line tool, were how system administrators used to log into remote servers. However, due to the fact that there is no encryption all communication, including passwords, are sent in plaintext meant that Telnet was abandoned in favour of SSH almost as soon as SSH was created.
For the purposes of logging into a remote server, you should never, and probably have never considered it. This does not mean that the telnet
command is not a very useful tool when used for debugging remote connection problems.
In this guide, we will explore using telnet
to answer the all too common question, “Why can’t I ###### connect‽”.
This frustrated question is usually encountered after installing a application server like a web server, an email server, an ssh server, a Samba server etc, and for some reason, the client won’t connect to the server.
telnet
isn’t going to solve your problem but it will, very quickly, narrow down where you need to start looking to fix your problem.
telnet
is a very simple command to use for debugging network related issues and has the syntax:
telnet
Because telnet
will initially simply establish a connection to the port without sending any data it can be used with almost any protocol including encrypted protocols.
There are four main errors that you will encounter when trying to connect to a problem server. We will look at all four, explore what they mean and look at how you should fix them.
For this guide we will assume that we have just installed a Samba server at samba.example.com
and we can’t get a local client to connect to the server.
Error 1 – The connection that hangs forever
First, we need to attempt to connect to the Samba server with telnet
. This is done with the following command (Samba listens on port 445):
telnet samba.example.com 445
Sometimes, the connection will get to this point stop and hang indefinitely:
telnet samba.example.com 445
Trying 172.31.25.31...
This means that telnet
has not received any response to its request to establish a connection. This can happen for two reasons:
- There is a router down between you and the server.
- There is a firewall dropping your request.
In order to rule out 1. run a quick mtr samba.example.com
to the server. If the server is accessible then it’s a firewall (note: it’s almost always a firewall).
Firstly, check if there are any firewall rules on the server itself with the following command iptables -L -v -n
, if there are none then you will get the following output:
iptables -L -v -n
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
If you see anything else then this is likely the problem. In order to check, stop