Telnet (Teletype Network)
Telnet is a network protocol used to virtually access a computer and to provide a two-way, collaborative and text-based communication channel between two machines.
It follows a user command Transmission Control Protocol/Internet Protocol (TCP/IP) networking protocol for creating remote sessions. On the web, Hypertext Transfer Protocol (HTTP) and File Transfer Protocol (FTP) simply enable users to request specific files from remote computers, while, through Telnet, users can log on as a regular user with the privileges they are granted to the specific applications and data on that computer.
Usage
telnet [options] hostname/IP address
Options
-4 | Force IPv4 address resolution. |
-6 | Force IPv6 address resolution. |
-8 | Request 8-bit operation. This option causes an attempt to negotiate the TELNET BINARY option for both input and output. By default, telnet is not “8-bit clean” (it does not recognize 8-bit character encodings such as Unicode). |
-E | Disables the escape character functionality; that is, sets the escape character to “no character”. |
-L | Specifies an 8-bit data path on output. This option causes the TELNET BINARY option to be negotiated on output. |
-a | Attempt automatic login. Currently, this sends the username via the USER variable of the ENVIRON option if supported by the remote system. The username is retrieved via the getlogin system call. |
-b address | Use bind on the local socket to bind it to a specific local address. |
-d | Sets the initial value of the debug toggle to TRUE. |
-r | Emulate rlogin. In this mode, the default escape character is a tilde. Also, the interpretation of the escape character is changed: an escape character followed by a dot causes telnet to disconnect from the remote host. A ^Z (Control-Z) instead of a dot suspends telnet, and a ^] (Control-close bracket, the default telnet escape character) generates a normal telnet prompt. These codes are accepted only at the beginning of a line. |
-S tos | Sets the IP TOS (type-of-service) option for the telnet connection to the value tos. |
-e escapechar | Sets the escape character to escapechar. If no character is supplied, no escape character will be used. Entering the escape character while connected causes telnet to drop to command mode. |
-l user | Specify user as the user to log in as on the remote system. By sending the specified name as the USER environment variable, so it requires that the remote system support the TELNET ENVIRON option. This option implies the -a option, and may also be used with the open command. |
-n tracefile | Opens tracefile for recording trace information. See the set tracefile command below. |
host | Specifies a host to contact over the network. |
port | Specifies a port number or service name to contact. If not specified, the telnet port (23) is used. |
Examples
- Check the listen port
You can use this command for check the connection of a application.
telnet IPADDRESS 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
# 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.