Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Networking

Linux telnet command

Reference for the Linux telnet command: why it is no longer used for remote login, and how it still helps to test TCP ports and speak simple text protocols by hand.

telnet is the oldest remote-login program on the Internet. It opens a TCP connection to a host and port and connects your keyboard and screen to it. As a login tool it is obsolete: everything, including your password, travels in clear text, so ssh replaced it decades ago.

It survives as a diagnostic. Because it simply opens a TCP connection and lets you type, it can check whether a port is reachable and let you talk to text protocols (HTTP, SMTP, POP3, Redis) by hand. Many systems no longer install it; nc or the Bash /dev/tcp feature do the same job.

Terminal
telnet HOST [PORT]

Try it

telnet is not installed in our sandbox, so this is read-only. A successful and a failed connection:

CONSOLE
$ telnet mail.example.org 25
Trying 203.0.113.25...
Connected to mail.example.org.
Escape character is '^]'.
220 mail.example.org ESMTP ready
HELO me.example.com
250 mail.example.org
QUIT
221 Bye
Connection closed by foreign host.

$ telnet 203.0.113.25 2525
Trying 203.0.113.25...
telnet: Unable to connect to remote host: Connection refused

The same hand-typed conversation can be done with Bash redirection against a small local server:

Bash Talking to a text service by hand

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
telnet [-46ac] [-l USER] [-e ESCAPE] [HOST [PORT]]
Argument Description
HOST Name or address to connect to.
PORT TCP port (default 23, the Telnet protocol). Give a number or a service name such as smtp.
-4, -6 Force IPv4 or IPv6.
-l USER Pass a user name to the remote login.
-e CHAR Change the escape character (default Ctrl-]).
-a, -c Auto-login with the current user; disable reading .telnetrc.

Escape prompt: press Ctrl-] to get the telnet> prompt; type quit (or close) to leave.

Returns: 0 after a normal session, 1 when the connection fails.

Usage notes

  • Never use it for logins. Passwords and data are sent unencrypted and can be read on the network. Use SSH.
  • It is a port test. "Connected to" means a TCP handshake completed. "Connection refused" means nothing listens (or a firewall rejected it); a long hang before "timed out" usually means a firewall silently dropped the packets.
  • Not for TLS ports. On 443 or 993 the server expects an encrypted handshake, so you will see garbage or a closed connection. Use openssl s_client instead.
  • Line endings. Most text protocols want \r\n. Telnet sends that when you press Enter in line mode; scripts using printf must add it explicitly.
  • Missing? Install it with sudo apt install telnet. On minimal servers you can use nc -zv HOST PORT, or Bash alone: (exec 3<>/dev/tcp/HOST/PORT) && echo open.
  • Not scriptable. Telnet is interactive, and piping into it gives odd results because of option negotiation. Use nc, /dev/tcp or expect for automation.