CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Network Transfer & Tools / telnet

telnet

Quick TCP port check (never for logins)

Beginnernetworktcplegacy

telnet opens a plain TCP connection to a host and port and lets you type into it. Its original job, remote login, is obsolete and insecure (everything is cleartext), but it remains a common way to check that a port accepts connections and to talk to text protocols such as HTTP and SMTP.

Syntaxtelnet HOST [PORT] (escape: Ctrl+] then 'quit')

Watch it run

A developer says the app can't reach Postgres. Check the port from the app server with the tool the runbook mentions.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 4
telnet 10.0.3.20 5432

'Connected' means the TCP handshake succeeded: the path and firewalls allow 5432 and something listens. Postgres waits for the client to speak first, so nothing more appears. Ctrl+] then quit leaves.

Anatomy of a command

$
commandtelnet

A TCP client that connects your keyboard and screen to the socket. On Ubuntu 24.04 it's from GNU inetutils.

How it works

telnet resolves the host, then calls connect() for each address it gets, printing 'Trying ADDRESS...'. When the TCP handshake completes it prints 'Connected to' and the escape character, then copies your keystrokes to the socket line by line and prints whatever the server sends. On port 23 it would also negotiate telnet options (terminal type, echo) with a telnet server, but on other ports it behaves like a raw TCP client. Nothing is encrypted: a telnet login sends the password in clear text, which is why SSH replaced it everywhere. To leave a connection that the server keeps open, press Ctrl+] to reach the telnet> prompt and type quit. For scripting, nc is better: it has timeouts, exits cleanly and reports through its exit code.

Options you'll actually use

HOST PORTConnect to PORT on HOST (default 23)
Ctrl+]Escape to the telnet> command prompt
quit / closeAt the telnet> prompt: exit / close the connection
-4 / -6Force IPv4 or IPv6
-b ADDRBind to a local source address

Common mistakes

Running a telnet server (port 23) for remote administration

Usernames, passwords and all commands travel in clear text and can be captured by anyone on the path.

Use SSH; uninstall telnetd.
Using telnet for port checks in scripts

It waits about two minutes on filtered ports, needs interaction to exit, and its exit code doesn't reflect success well.

nc -z -w 3 host port # or timeout 3 bash -c '</dev/tcp/host/port'
Getting stuck in a connection and pressing Ctrl+C repeatedly

Ctrl+C is sent to the server; telnet's escape key is Ctrl+].

Ctrl+] then type quit

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Use telnet to connect to port 22 on localhost and read the SSH banner, then leave the session.

  2. 2

    Without telnet or nc, test whether TCP port 22 on localhost is open, giving up after 3 seconds.

Related commands

ncTest ports and move raw bytes over TCP/UDPnmapScan hosts and ports, detect servicessshLog in to remote servers securelycurlMake HTTP requests and debug APIs
PreviousnmapNextiptables
Linux / Network Transfer & Tools / telnet

telnet

Quick TCP port check (never for logins)

Beginnernetworktcplegacy

telnet opens a plain TCP connection to a host and port and lets you type into it. Its original job, remote login, is obsolete and insecure (everything is cleartext), but it remains a common way to check that a port accepts connections and to talk to text protocols such as HTTP and SMTP.

Syntaxtelnet HOST [PORT] (escape: Ctrl+] then 'quit')

Watch it run

A developer says the app can't reach Postgres. Check the port from the app server with the tool the runbook mentions.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 4
telnet 10.0.3.20 5432

'Connected' means the TCP handshake succeeded: the path and firewalls allow 5432 and something listens. Postgres waits for the client to speak first, so nothing more appears. Ctrl+] then quit leaves.

Anatomy of a command

$
commandtelnet

A TCP client that connects your keyboard and screen to the socket. On Ubuntu 24.04 it's from GNU inetutils.

How it works

telnet resolves the host, then calls connect() for each address it gets, printing 'Trying ADDRESS...'. When the TCP handshake completes it prints 'Connected to' and the escape character, then copies your keystrokes to the socket line by line and prints whatever the server sends. On port 23 it would also negotiate telnet options (terminal type, echo) with a telnet server, but on other ports it behaves like a raw TCP client. Nothing is encrypted: a telnet login sends the password in clear text, which is why SSH replaced it everywhere. To leave a connection that the server keeps open, press Ctrl+] to reach the telnet> prompt and type quit. For scripting, nc is better: it has timeouts, exits cleanly and reports through its exit code.

Options you'll actually use

HOST PORTConnect to PORT on HOST (default 23)
Ctrl+]Escape to the telnet> command prompt
quit / closeAt the telnet> prompt: exit / close the connection
-4 / -6Force IPv4 or IPv6
-b ADDRBind to a local source address

Common mistakes

Running a telnet server (port 23) for remote administration

Usernames, passwords and all commands travel in clear text and can be captured by anyone on the path.

Use SSH; uninstall telnetd.
Using telnet for port checks in scripts

It waits about two minutes on filtered ports, needs interaction to exit, and its exit code doesn't reflect success well.

nc -z -w 3 host port # or timeout 3 bash -c '</dev/tcp/host/port'
Getting stuck in a connection and pressing Ctrl+C repeatedly

Ctrl+C is sent to the server; telnet's escape key is Ctrl+].

Ctrl+] then type quit

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Use telnet to connect to port 22 on localhost and read the SSH banner, then leave the session.

  2. 2

    Without telnet or nc, test whether TCP port 22 on localhost is open, giving up after 3 seconds.

Related commands

ncTest ports and move raw bytes over TCP/UDPnmapScan hosts and ports, detect servicessshLog in to remote servers securelycurlMake HTTP requests and debug APIs
PreviousnmapNextiptables