Telnet basics
What Telnet is, how options are negotiated, and why it should not carry passwords on its own.
Telnet (RFC 854) is the old protocol for a remote text terminal over TCP. TN3270 and TN5250 are built on it, and it is still used for some VT hosts, network equipment and test machines.
Not encrypted
Telnet sends everything in clear text, including your password. Use it only on trusted networks. For VT sessions prefer SSH. For 3270 and 5250 use TLS where the host supports it.
The Network Virtual Terminal
Telnet defines a simple NVT: 7-bit text, a few control codes and the character 255 (IAC, "interpret as command") that starts a Telnet command. A real 255 byte in the data is sent twice.
Option negotiation
Both sides agree on options with four verbs:
WILL x I want to do option x
WON'T x I will not
DO x please do option x
DON'T x please do not
An option may then send details in a subnegotiation: IAC SB option ... IAC SE. For the byte values and how to read a negotiation log, see Telnet IAC codes: reading FF FB 01, WILL, WONT, DO and DONT in a trace.
Options you meet
0 Binary transmission
1 Echo
3 Suppress go ahead
24 Terminal type (RFC 1091)
25 End of record (3270, 5250)
31 Window size (NAWS) (RFC 1073)
39 NEW-ENVIRON (RFC 1572; used by 5250 for device names)
40 TN3270E (RFC 2355)
The IANA registry lists all of them (see VT and terminal links).
Ports
- 23 is the default Telnet port.
- 992 is the usual port for Telnet over TLS.
- Hosts can use any port. 3270, 5250 and VT services often run on different ports of the same machine.
- To test whether a port is open without a Telnet client, see Check if a TCP port is open without Telnet: nc, Test-NetConnection, bash.
Troubleshooting
- A screen full of strange characters at connect time can be unprocessed Telnet commands. The client did not answer the negotiation, or you connected to a non-Telnet service.
- If the connection closes right away, the host may need a specific option (terminal type, TN3270E, NEW-ENVIRON) that the client did not offer.
Related
- TN3270E
- 5250 devices
- TERM and terminfo
- Standards and manuals
- Telnet echo, typed characters twice, missing or visible passwords
- Telnet "Connection closed by foreign host"
- Check if a TCP port is open without Telnet: nc, Test-NetConnection, bash
- Telnet IAC codes: reading FF FB 01, WILL, WONT, DO and DONT in a trace
- Turn on the Telnet client in Windows: "telnet is not recognized"