How to use Telnet and Netcat commands to test Port connectivity

September 5, 2025 / Command Line

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:

  1. Using Telnet
    This command is used to connect to a server on a specific port.

    1. The syntax for it is as follows:
      telnet <hostname or IP> <port>
    2. Below is an example of a telnet command:
      telnet sample.com 80
    3. If the port is open, you will see a connection message as given below:
      Connected to sample.com.
      Escape character is ‘^]’.
    4. If the port is closed or blocked, you will get a failure message:
      telnet: Unable to connect to remote host: Connection refused
    5. 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
  2. Using nc (Netcat)
    The netcat (nc) utility is a powerful networking tool that can also test port connectivity.

    1. The syntax for it is as follows:
      nc -zv <hostname or IP> <port>
    2. Below is an example of the netcat command:
      nc -zv sample.com 443

      z ? Zero-I/O mode (used for scanning)
      v ? Verbose output

    3. If the port is open, you will get the output:
      Connection to sample.com 443 port [tcp/https] succeeded!
    4. And, if the port is closed, you will see output as:
      nc: connect to sample.com port 443 (tcp) failed: Connection refused
    5. If nc is not installed, install it using:
      sudo apt install netcat # Ubuntu/Debian
      sudo yum install nc         # CentOS/RHEL

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.

Testing ports and network connectivity?
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

Spread the love