How to Check if Ports are Open in Linux

Table of Contents
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:
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:
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:
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:
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.
LATEST POSTS
-
How to Install PHP 7.2 on Debian 10
-
How to Change Hostname on Ubuntu 18.04
-
How to Use Linux Screen Command With Examples
-
How to install Composer on Ubuntu 18.04
-
How to Install MySQL on Fedora 29
-
How to Start, Stop and Restart Apache Server
-
How to Use Shutdown Command in Linux
-
How to Install RubyMine on Ubuntu 18.04
-
How to Install Netbeans on Ubuntu 18.04
-
17 Best Practical Examples of ls Command in Linux
-
How to install Java on Ubuntu 18.04
-
How to Install PHP on Ubuntu 18.04