Whenever diagnosing network issues, it becomes necessary to check whether a specific port on a server is open and available. For this purpose, two commonly used tools are ‘telnet’ and ‘netcat(nc)’.
This guide will show you how to use both tools to test port connectivity.
Let us follow the guide to explore the two commands:
- Using Telnet
This command is used to connect to a server on a specific port.- The syntax for it is as follows:
telnet <hostname or IP> <port>
- Below is an example of a telnet command:
telnet sample.com 80
- If the port is open, you will see a connection message as given below:
Connected to sample.com. Escape character is ‘^]’.
- If the port is closed or blocked, you will get a failure message:
telnet: Unable to connect to remote host: Connection refused
- On some Linux distributions, telnet is not installed by default. You can install it using:
sudo apt install telnet # Ubuntu/Debian sudo yum install telnet # CentOS/RHEL
- The syntax for it is as follows:
- Using nc (Netcat)
The netcat (nc) utility is a powerful networking tool that can also test port connectivity.- The syntax for it is as follows:
nc -zv <hostname or IP> <port>
- Below is an example of the netcat command:
nc -zv sample.com 443
z ? Zero-I/O mode (used for scanning)
v ? Verbose output - If the port is open, you will get the output:
Connection to sample.com 443 port [tcp/https] succeeded!
- And, if the port is closed, you will see output as:
nc: connect to sample.com port 443 (tcp) failed: Connection refused
- If nc is not installed, install it using:
sudo apt install netcat # Ubuntu/Debian sudo yum install nc # CentOS/RHEL
- The syntax for it is as follows:
This way, you can use Telnet and Netcat commands to test Port connectivity. It helps in diagnosing problems with the network and service availability. If you run into any difficulty, feel free to contact our support staff.
For complete control over ports and services, consider using a VPS with full network access.
Want to go beyond testing ports? Learn How to Scan Open Ports on a Remote Server in Linux