Table of Contents

Linux Commands#network

telnet - How to use telnet command in Linux with examples



telnet - user interface to the TELNET protocol



Check the listen port

You can use this command for check the connection of a application.

telnet IPADDRESS PORT
curl -v telnet://<host>:<port>

telnet 192.168.0.10 80  <- http
telnet 192.168.0.10 25  <- smtp

Check Connection and Close Connection.

# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 office-sv1 ESMTP Sendmail 8.13.8/8.13.8; Mon, 28 Mar 2011 08:01:08 +0900
^]                                 <- Ctrl ]
telnet> quit
Connection closed.




Web Server

GET Method

GET / HTTP/1.0   <- http://HOST/index.html
GET / HTTP/1.1
GET /test/sample.html  HTTP/1.0  <- http://HOST/test/sample.html


Example

# telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.joeswebhosting.net (127.0.0.1).
Escape character is '^]'.
GET / HTTP/1.0                       <-  Enter 2 times (http://localhost/index.html)

HTTP/1.1 200 OK
Date: Wed, 29 Jul 2009 15:16:50 GMT
Server: Apache/1.3.37 (Unix) mod_fastcgi/2.4.6 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.4.7 abbr.
Last-Modified: Mon, 05 Feb 2007 11:04:57 GMT
ETag: "1b200-b2c-45c70f59"
Accept-Ranges: bytes
Content-Length: 2860
Connection: close
Content-Type: text/html

<html>
<html>
<title>TEST</title>

abbr.

</body>
</html>
Connection closed by foreign host.
#


Mail Server

send mail

# telnet localhost 25
Trying 127.0.0.1...
Connected to test-server.test-server (127.0.0.1).
Escape character is '^]'.
220 test-server.example-sec.local ESMTP
helo localhost
250 test-server.example-sec.local
mail from:user01@example-sec.jp
250 ok
rcpt to:user02@example-sec.jp
250 ok
502 unimplemented (#5.5.1)
data
354 go ahead
From: user01@example-sec.jp
To: user02@example-sec.jp
Subject: test
this is test.

.
250 ok 1184072108 qp 20747

502 unimplemented (#5.5.1)
quit
221 test-server.example-sec.local
Connection closed by foreign host.