How to Check if Ports are Open in Linux


Check if Ports are Open in Linux

There is a number of ports in the Linux System. Most of the time it is required to check open ports on systems Network Interface. In this tutorial, you are going to learn How to Check if Ports are Open in Linux.

Quick Note

You can check Open ports in Linux using utilities like netstat, ss, lsof and nmap etc. On the latest version of Linux system the ss command is mainly used.
You following commands to check if ports are open in Linux.

Check open ports by using nmap command:

sudo nmap -sTU -O ENTER-IP-ADDRESS

Use the following ss command on Latest versions of Linux:

ss -tulwn

Below are the examples of nmap and lsof commands.

sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN

1. Checking open ports using nmap command

The nmap is a powerful network scanning tool used for penetration testing and security audits. It is used to scan single hosts as well as large networks.

The basic syntax for checking open ports with nmap is given below:

sudo nmap -sTU -p- ENTER_IP_ADDRESS

The following nmap command shows all the open ports of TCP and UDP addressing localhost (127.0.0.1):

sudo nmap -sTU -p- 127.0.0.1

The output should be:

"How

2. Check open ports with lsof Command

To check open ports with lsof command along with grep command you can type the following command in the terminal:

sudo lsof -i -P -n | grep LISTEN

The output should be:

"How

3. Check open ports with ss command

The ss command is also used to check open listening ports in Linux. As the netstat command is deprecated for some time. You should use ss command instead:

The following ss command shows all listening open ports on your system:

sudo ss -tulwn

The output should be:

"How

4. Check listening ports with netstat Command

You can check which ports are open on your system by using netstat command. To do so you can enter following command:

netstat -tulpn | grep LISTEN

The output should be:

"How

Note: The netstat command on some systems is deprecated for some time. So you can use ss command as given in the above points.

Conclusion

You have successfully learned How to Check if Ports are Open in Linux. If you have any queries please don’t forget to comment below.