Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

Test a Port with Telnet

telnet 203.0.113.10 443

The command connects to the host and TCP port you name and links your keyboard to the connection. If the port is open, you see that the connection was made; if not, you get an error or a long wait. Use it only against hosts you own or administer: testing ports on other people's systems can break their rules or the law.

Install the Telnet Client

Most current server images do not include it. Install the client only; you do not need a Telnet server:

sudo apt install telnet

That is for Ubuntu and Debian. On AlmaLinux and Rocky Linux:

sudo dnf install telnet

On current Debian and Ubuntu releases the telnet package installs the inetutils client; the command is the same. If you would rather not add a package, use nc or curl, shown at the end of this guide; they do the same job.

Read the Result

  • Connected: telnet prints that it is connected and names the escape character. The port is open, and any lines that follow are what the service sends.
  • Connection refused: the host answered, but nothing listens on that port, or a firewall rejects the connection.
  • Only "Trying" and then a timeout: the packets are dropped, usually by a firewall, or the host is down or the address is wrong.
  • A name resolution error: the host name does not resolve; check it with the dig command.

See What a Service Says

Many services greet you as soon as you connect. An SSH server sends one line with its protocol and software version:

telnet 203.0.113.10 22

A web server waits for a request. Connect to port 80, type the two request lines below, then press Enter once more on an empty line:

telnet example.com 80
GET / HTTP/1.1
Host: example.com

The server answers with a status line and headers, as described in HTTP status codes. Port 443 also connects, but that service expects TLS, so typed text gets no useful answer; use openssl s_client there.

Leave the Session

Press Ctrl and ] together to reach the telnet prompt, then type quit and press Enter. If the service has already closed the connection, telnet exits by itself.

Why Telnet Is Not for Logins

Telnet was once the standard way to log in to remote systems. It sends everything as plain text, including the user name and password, so anyone on the path can read them. SSH replaced it for that purpose. Do not run a Telnet server on a machine reachable from the internet.

TelnetSSH
EncryptionNoneAlways
Default port2322
LoginPassword, in plain textPassword or key
Use todayPort testsLogins, file transfer, tunnels

To log in to a server, see how to SSH into a server.

Alternatives: nc and curl

nc is often already installed and suits scripts better, because it exits by itself. On AlmaLinux and Rocky Linux it comes from the nmap-ncat package, which also supports these options:

nc -zv 203.0.113.10 443
nc -zv -w 5 203.0.113.10 3306

-z checks the port without sending data, -v prints the result, and -w sets a timeout in seconds; see the nc command. curl can open a raw TCP connection too, and for web ports it shows the whole exchange:

curl -v telnet://203.0.113.10:22
curl -v https://example.com/

Press Ctrl and C to end the curl session. To see from the inside which ports your server listens on, use ss; see how to check open ports in Linux.

Was this answer helpful?
Loading...