Troubleshooting Linux Servers with telnet

Completely Insecure But Still Useful

The venerable telnet is still a useful tool in the server administrator's toolkit. Juliet Kemp shows how to test basic SMTP, IMAP, HTTP, and IRC server functions with telnet.

Telnet is one of the older ways of doing business over a network: a
network protocol running over TCP/IP, which allows a client to talk to a
server remotely. Back in the day (such as when I first got online), telnet
was the usual means to connect to a remote computer to get a console, and from there do server administration, check email, and run applications.
These days ssh is the default for security reasons, but telnet still has
its uses. Because telnet transmits all data as-is you can use it to open a
raw TCP session, then talk to a server running a network service, and do a
little debugging. At the very least, telnetting to a particular port on a
server can confirm that you can reach the remote server from your machine, and
that there is a running service bound to the port.

It's important to remember that telnet is NOT encrypted, so it's very
vulnerable to packet-sniffing and man-in-the-middle attacks. You should never
use it to transmit a username and password except for controlled tests using disposable accounts.

SMTP

SMTP servers run on port 25, and you can use telnet to talk to them
directly:

telnet smtp.example.com 25

Note that you won't get anything that looks like a prompt as the server
doesn't expect to interact with humans. Instead, you'll get a couple of
lines of output, then a blank line waiting for you to initiate the connection.
Type:

to register on the server for the domain example.com.
EHLO initiates the conversation with the remote server, tells it the
host's name, and specifies that the host wants to use the extended SMTP
protocol (to use the regular SMTP protocol, use HELO instead). See this site for a useful summary of SMTP server commands.

Your connection is now established, so you can try sending a mail directly.

MAIL From:
RCPT To:
DATA

At this point, you can type your message in. When you're done, hit return,
then type . and hit return again to send the message. Type
QUIT to leave the session.

This can be a useful way to check what's happening with your SMTP server.
Some SMTP servers require TLS, which means that you won't be able to get any
further than initiating the connection. But you can
at least check that the server is there and taking connections. (The OpenSSL s_client test program is for testing TLS connections on mail servers; come back tomorrow for a s_client howto.)

IMAP

Similarly, you can talk directly to an IMAP server to find out what's going
on there:

telnet localhost 143

Once the connection is established, you'll get a bunch of output that looks a
bit like this: