Troubleshooting Linux Servers with telnet
Completely Insecure But Still UsefulThe 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.
SMTP servers run on port 25, and you can use telnet to talk to them directly:
telnet smtp.example.com 25Note 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:
EHLO example.comto 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: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.
RCPT To: DATA
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.)
Similarly, you can talk directly to an IMAP server to find out what's going on there:
telnet localhost 143Once the connection is established, you'll get a bunch of output that looks a bit like this:
Connected to imap.example.com. Escape character is '^]'. * OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION] Courier-IMAP ready. Copyright 1998-2010 Double Precision, Inc. See COPYING for distribution information.To log in, use this (note that the 1 is needed):
1 LOGIN username passwordNote: this password is going across in the clear! If you definitely want to do this, use a disposable test account and get rid of it afterwards.
Here are a few more commands to try, from WikiQuestions:
- 1 SELECT Inbox will select the Inbox folder. Look for the EXISTS line of output to tell you how many mails there are.
- 4 LIST "" "INBOX" will list each item in the inbox, with various pieces of information about the items including the date sent, any flags on the mail, and the subject line.
- 1 LOGOUT will log you out.
- 1Linux Top 3: Fedora 24, Peppermint 7 and Solus 1.2
- 2Linux Top 3: Alpine Linux 3.4, deepin 15.2 and Linux Lite 3.0
- 3Linux 4.7 Set to Boost Live Patching, Security and Power Management
- 4Linux 4.6 Charred Weasel adds USB 3.1 Support
- 5Linux Top 3: OpenIndiana 2016.04, Ubuntu 16.04 and Debian's New Leader