5 Best Ways to Check If a Port is Open on a Remote Linux PC

Port (also called channels) is the crucial part of the network for transferring data. These ports are used by the protocols available on the network, such as File Transfer Protocol (FTP) uses port 21. In Linux, there are various ways to check whether the port is open on a remote host.

This article will demonstrate 5 different methods to check the open port on a remote host. The content for the post is:

Method 1: Check the Open Port Through Telnet

The first method for checking the open ports in Linux is by using the “telnet” utility. The “telnet” is a utility for connection with a remote host that can be installed with the given command.

For Debian/Ubuntu:

$ sudo apt install telnetd

The telnet service will be installed.

For Fedora/CentOS/RHEL:

$ sudo yum install telnetd

To check if the port on a remote host is open, run the “telnet” command with the remote host IP address and the port number:

$ telnet 192.168.64.131 23

The successful connection with the port shows that port 23 is open.

Let’s move toward method 2.

Method 2: Check the Open Port Through Netcat (nc)

The second method to check the open port is to use the Netcat (nc) utility. It is a utility for scanning the ports and sending data through UDP and TCP protocols. To install “nc” in Linux, use the given command:

For Debian/Ubuntu:

$ sudo apt install netcat

For Fedora:

$ sudo dnf install nc

For RHEL/CentOS:

$ sudo yum install nc

Run the “nc” command with IP address of the remote host and port number you want to check:

$ nc -zv 192.168.64.131 22

The successful connection shows that SSH port 22 is open.

Method 3: Check the Open Port Through Nmap

Another method to check the open port in Linux is through the “nmap” tool. The “nmap” is the networking tool for scanning the network connection to check the port status. To install it, use the following command according to your Linux distribution.

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

To check the open port in Linux using the “nmap” tool, use the “F” option with remote host 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.

Method 4: Check the Open Port Through Netstat

Using the “netstat” command, the open port in Linux can also be checked. The “netstat” is a utility used for displaying the connection, interface statistics, and other tasks related to the network. Use the given command; it will display the list of IP addresses.

$ netstat -tuplen

In the above image, protocols having “Listen” status are the open ports.

Method 5: Check the Open Port Through /dev/tcp

The last method to check the open ports is to use the “/dev/tcp” command. Use the following syntax for the command.

Syntax:

$ echo > /dev/tcp/[host]/[port] && echo "Port is open"
Or 
$ echo > /dev/udp/[host]/[port] && echo "Port is open"

To use this command, enter the remote host IP address and the port number to check. If the port is open, then the command will return true, and our “echo” statement will be executed:

$ echo > /dev/tcp/192.168.64.131/23 && echo "Port is open"

The port 23 is in the open state.

Conclusion

In Linux, to check the port is in the open state, use the “telnet”, “Netcat (nc)”, “nmap”, “netstat,” or “/dev/tcp” command. For checking the open port through “telnet”, “nmap”, “netstat,” and “/dev/tcp,” type it in the terminal with the host IP address and the port number to check. This write-up has illustrated the methods for checking the open ports in Linux.