How to Test if a Port on a Remote System is Reachable?

Ports are a crucial part of the network, which are also known as channels used for communicating and transferring data over an internet connection. Various ports are used for different protocols, such as the 21 ports used by FTP and port 22 used by SFTP protocol. Users can use these ports for the connection with the remote host. There are three methods to test if the port is reachable.

This post will demonstrate these three methods to test whether the remote system port is reachable. The content for the article is:

Method 1: Using Nmap Test if the Port on Remote Host is Reachable

The first method to check if the port is reachable or not is to use the Nmap tool. The “Nmap” is a tool for scanning the network connection, which allows testing whether the port is reachable. To install the Nmap tool, run the below command in the terminal.

For Debian/Ubuntu:

$ sudo apt install nmap

The Nmap tool will be installed.

For Fedora:

$ sudo dnf install nmap

For CentOS/RHEL:

$ sudo yum install nmap

After the installation of the Nmap tool, scan the ports using the “F” flag with the remote server IP address:

$ sudo nmap -F 192.168.64.131

The output of the above image shows that ports 23 and 80 are in the open state.

Note: You can also use the below command for scanning the port, which will give the same output, but this will take some time. The “F” flag is used for the fast scan.

In contrast, the “sT” flag is used for the deep scan (TCP Connect Scan):

$ sudo nmap -sT 192.168.43.216

The users can even test a specific port to see if it is reachable or not by using the “-p” flag and then typing the port number to test:

$ sudo nmap 192.168.43.216 -p 21

The state of port 21 is filtered, which means a firewall or other network blocks the port.

Method 2: Using Telnet Test if the Port on Remote Host is Reachable

The second method that can be utilized for testing if the port on the remote host is reachable or not is using the Telnet service. The Telnet is a utility used for connecting to the remote host. To install Telnet in the Linux operating system, run the following command:

For Debian/Ubuntu:

$ sudo apt install telnetd

The telnet service will be installed.

For Fedora/CentOS/RHEL:

$ sudo yum install telnetd

To check the port on a remote host is reachable or not, run the “telnet” command with the remote host IP address and the port you want to check:

$ telnet 192.168.64.131 23

The successful connection with the port shows that the port is open and reachable.

Let’s try port 80 using the “telnet” command:

$ telnet 192.168.64.131 80

The above image represents that port 80 is closed and not reachable.

Method 3: Using Netcat Test if the Port on Remote Host is Reachable

The third method to test whether the remote host’s port is reachable is the “Netcat” utility. The “Netcat” is a built-in utility for scanning the ports and sending data through TCP or UDP protocols. Execute the “nc” command with the IP address of the remote host and the port number you want to check:

$ nc -zv 192.168.64.131 22

It is clear that port 22 is opened and reachable.

Let’s check the port 20 is reachable or not:

$ nc -zv 192.168.64.131 20

The port 20 is closed and not reachable.

Conclusion

In Linux, to test if a port on a remote host is reachable or not, use the “nmap” tool, “telnet” service, or “nc” command in the terminal. Install the Nmap tool and run the “nmap” utility with the remote host IP address and port number. Similarly, to use the “telnet” or the “nc” utility, run it with the IP address and the port you want to check. This write-up has illustrated the methods to test whether a port on the remote host is reachable.