How to Check if a TCP port is open using telnet
Introduction
This guide details how to check if a remote port is open using telnet.
What is telnet?
Telnet is a now-outdated protocol first developed in 1969 and often used to control computers from a remote location over a command line interface. Telnet has been superseded by ssh for this purpose due to its lack of security and authentication by default. However, as telnet has been ported to most operating systems and connects using TCP it is a useful tool for troubleshooting.
Installing telnet
On Debian:
sudo apt install telnet
On Centos or AlmaLinux
yum install telnet
Testing a remote port
Telnet can be used to check if a remote port is open which is great for testing firewall rules are working as expected or if services are running. To test a host with IP 11.22.33.44 on port 80 run
telnet 11.22.33.44 80
If the port is open then you should see something like:
[root@host~]# telnet 11.22.33.44 80 Trying 111.222.33.44... Connected to 11.22.33.44. Escape character is '^]'.
If the port specified is not open then you would expect to see telnet state that it is trying to connect but then hanging or explicitly stating that the connection has been refused.
Either:
[root@host~]# telnet 11.22.33.44 80 Trying 11.22.33.44...
or
[root@host~]# telnet 11.22.33.44 80 Trying 11.22.33.44... telnet: connect to address 11.22.33.44: Connection refused