Build a local Telnet lab

Connect and use command mode

Open the local connection, send terminal data, and leave the session through the client command escape.

Keep the server from the previous lesson running. Open another terminal and connect:

telnet 127.0.0.1 2323

The client prints a few lines before you type anything:

Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Welcome

Each line tells you something. Trying means a TCP connection attempt is in progress. Connected means the handshake completed. Welcome is the first data your server sent. The escape character line matters most, and we will come back to it in a moment.

Now type hello and press Enter. Switch to the server terminal. It prints the received bytes in hexadecimal:

68656c6c6f0d0a

That is hello in ASCII, followed by 0d0a: carriage return and line feed. Back in the client, you see the server reply, Received 7 bytes. You typed five characters and the line ending added two more. This is the NVT new line from the foundations module, showing up in your own log.

Command mode

A Telnet client also has a local command mode, where you talk to the client program instead of the server. The default escape is usually Ctrl+], which is what '^]' meant in the connection banner. Press it and the client shows its own prompt:

telnet> 

You are now talking to the client, not the server. Type status to inspect the connection. It reports the connected host and the current escape character. Press Enter on an empty line to return to the session, or type quit to close the connection and exit.

The escape character is handled entirely by the client. It is never sent to the server as terminal data. Check your server’s hex log after pressing it: nothing new appears.

Three layers to keep apart

This gives you three kinds of “command” that are easy to confuse:

  • client commands like status and quit live in the client program only
  • Telnet protocol commands travel inside the stream as IAC sequences
  • ordinary terminal data is everything else you type

Only the last two ever reach the server. The first never leaves your machine.

One common confusion. If you stop the server while the client sits in command mode, the client may not notice until you return to the session and press a key. TCP only reports a closed connection when you try to use it. Nothing is broken. That is just how sockets work.

Lesson completed