pavement

Daemons, testing via Telnet

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
 
m (Reverted edits by 189.11.71.202 (Talk); changed back to last version by Jimbo)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
The [[telnet]] client can be used to interact directly with service daemons which use human-readable communications protocols - such as [[IMAP]], [[SMTP]], [[POP3]], or [[HTTP]] - and make sure they're doing what they are supposed to do.  This is an '''extremely''' valuable troubleshooting tool, as the experienced admin can see the exact communication from the server rather than rely on "friendly" but often inaccurate error messages given by client utilities intended for end users.
 
The [[telnet]] client can be used to interact directly with service daemons which use human-readable communications protocols - such as [[IMAP]], [[SMTP]], [[POP3]], or [[HTTP]] - and make sure they're doing what they are supposed to do.  This is an '''extremely''' valuable troubleshooting tool, as the experienced admin can see the exact communication from the server rather than rely on "friendly" but often inaccurate error messages given by client utilities intended for end users.
  
==Testing an SMTP service via telnet==
+
For more information, see the articles for testing each service:
  
ph34r# '''telnet localhost 25'''
+
[[SMTP, testing via Telnet]]
Trying 127.0.0.1...
+
Connected to localhost.localdomain.
+
Escape character is '^]'.
+
220  ESMTP
+
'''HELO justtesting'''
+
250
+
'''MAIL FROM: me@telnettingin.com'''
+
250 ok
+
'''RCPT TO: postmaster@mail.getsdeliveredhere.net'''
+
250 ok
+
'''DATA'''
+
354 go ahead
+
'''To: postmaster@mail.getsdeliveredhere.net'''
+
'''From: telnetclient@mail.getsdeliveredhere.net'''
+
'''Subject: this is a test message'''
+
'''Date: Thu, 21 Jun 2007 11:11:40 -0400'''
+
'''Just testing SMTP functionality by telnetting in to port 25.  I'll end this message now'''
+
'''by entering in a line with nothing but a period in it and hitting return.'''
+
'''.'''
+
250 ok 1103093638 qp 87827
+
'''QUIT'''
+
221
+
Connection closed by foreign host.
+
  
Okay - our [[SMTP]] server just accepted a telnet connection, responded like a mailserver, and accepted a nice little test email for delivery.  (Any response other than a '''250 ok''' would represent an error of one sort or another.)
+
[[IMAP, testing via Telnet]]
  
==Testing an IMAP service via telnet==
+
[[POP3, testing via Telnet]]
  
ph34r# '''telnet localhost 143'''
+
[[HTTP, testing via Telnet]]
Trying 127.0.0.1...
+
Connected to localhost.localdomain.
+
Escape character is '^]'.
+
* OK dovecot ready.
+
'''A LOGIN postmaster@mail.getsdeliveredhere.net thisismypassword'''
+
A OK logged in.
+
'''A SELECT inbox'''
+
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
+
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
+
* 1 EXISTS
+
* 1 RECENT
+
* OK [UIDVALIDITY 1103088195] UIDs valid
+
* OK [UIDNEXT 1] Predicted next UID
+
A OK [READ-WRITE] Select completed.
+
'''A LOGOUT'''
+
* BYE Logging out
+
A OK Logout completed.
+
Connection closed by foreign host.
+
  
Okay - we've just verified on a very direct level that the [[IMAP]] server we connected to answers incoming connections, successfully authenticates users, ''and'' successfully opens their inboxes - see the '''* 1 EXISTS''' and '''* 1 RECENT''' lines?  That tells us that there is a single email in the inbox folder, and it hasn't been read yet.
 
  
==Testing a POP3 service via telnet==
 
 
ph34r# '''telnet localhost 110'''
 
Trying 127.0.0.1...
 
Connected to localhost.localdomain.
 
Escape character is '^]'.
 
+OK dovecot ready.
 
'''USER postmaster@mail.getsdeliveredhere.net'''
 
+OK
 
'''PASS thisismypassword'''
 
+OK Logged in.
 
'''LIST'''
 
+OK 1 messages:
 
1 354
 
.
 
'''QUIT'''
 
+OK Logging out.
 
Connection closed by foreign host.
 
 
Confirmed - the [[POP3]] server answers connections, authenticates users, and can access its mail store - in this case, we can see that there is a message queued up and waiting for delivery.  (Note that frequently you may NOT see any messages in the queue on a POP3 server, as most organizations using POP3 expect users to download their mail and delete it as soon as they have.)
 
 
==Testing an HTTP service via telnet==
 
 
ph34r# '''telnet testdomain.tld 80'''
 
Trying 192.168.0.252...
 
Connected to testdomain.tld.
 
Escape character is '^]'.
 
'''GET <nowiki>http://www.testdomain.tld/</nowiki>'''
 
&lt;html>&lt;body>&lt;h1>It works!&lt;/h1>&lt;/body>&lt;/html>
 
Connection closed by foreign host.
 
 
In this case, we connected to a fictious webserver and asked it to serve us its home page.  Note the response - that's a recent Apache "congratulations" page, meaning that the server hasn't really been configured properly (yet).  (Usually, you'll get a MUCH longer response - typical [[HTML]] pages these days run 150K+ in size in code alone!)
 
 
Note that the '''GET''' command is in all caps - Apache is very particular about capitalization, and will not understand [[HTTP]] commands which are not in all caps!
 
 
What happens if we ask for a page that doesn't exist?
 
 
ph34r# '''telnet testdomain.tld 80'''
 
Trying 192.168.0.250...
 
Connected to testdomain.tld.
 
Escape character is '^]'.
 
'''GET <nowiki>http://testdomain.tld/doesntexist.html</nowiki>'''
 
&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
 
&lt;html>&lt;head>
 
&lt;title>404 Not Found&lt;/title>
 
&lt;/head>&lt;body>
 
&lt;h1>Not Found&lt;/h1>
 
&lt;p>The requested URL /doesntexist.html was not found on this server.&lt;/p>
 
&lt;hr>
 
&lt;address>Apache/2.0.52 (FreeBSD) PHP/5.2.1 with Suhosin-Patch Server at testdomain.tld Port 80&lt;/address>
 
&lt;/body>&lt;/html>
 
Connection closed by foreign host.
 
  
 
[[Category:Common Tasks]]
 
[[Category:Common Tasks]]

Latest revision as of 09:48, 22 May 2009

The telnet client can be used to interact directly with service daemons which use human-readable communications protocols - such as IMAP, SMTP, POP3, or HTTP - and make sure they're doing what they are supposed to do. This is an extremely valuable troubleshooting tool, as the experienced admin can see the exact communication from the server rather than rely on "friendly" but often inaccurate error messages given by client utilities intended for end users.

For more information, see the articles for testing each service:

SMTP, testing via Telnet

IMAP, testing via Telnet

POP3, testing via Telnet

HTTP, testing via Telnet

Personal tools