4 Ways to Find Out What Ports Are Listening in Linux

The state of a port is either openfilteredclosed, or unfiltered. A port is said to be open if an application on the target machine is listening for connections/packets on that port.

In this article, we will explain four ways to check open ports and also will show you how to find which application is listening on what port in Linux.

1. Using Netstat Command

Netstat is a widely used tool for querying information about the Linux networking subsystem. You can use it to print all open ports like this:

$ sudo netstat -ltup 

The flag -l tells netstat to print all listening sockets, -t shows all TCP connections, -u displays all UDP connections and -p enables printing of application/program name listening on the port.

Check Open Ports Using Netstat Command

Check Open Ports Using Netstat Command

 

To print numeric values rather than service names, add the -n flag.

$ sudo netstat -lntup

Show Numeric Values

Show Numeric Values

You can also use grep command to find out which application is listening on a particular port, for example.

$ sudo netstat -lntup | grep "nginx"

Find Port of Running Application

Find Port of Running Application

Alternatively, you can specify the port and find the application bound to, as shown.

$ sudo netstat -lntup | grep ":80"

Find Application Using a Port Number

Find Application Using a Port Number

2. Using ss Command

ss is another useful tool for displaying information about sockets. It’s output looks similar to that of netstat. The following command will show all listening ports for TCP and UDP connections in numeric value.

$ sudo ss -lntu

Find Open Ports Using ss Command

Find Open Ports Using ss Command

3. Using Nmap Command

Nmap is a powerful and popular network exploration tool and port scanner. To install nmap on your system, use your default package manager as shown.

$ sudo apt install nmap  [On Debian/Ubuntu]
$ sudo yum install nmap  [On CentOS/RHEL]
$ sudo dnf install nmap  [On Fedora 22+]

To scan all open/listening ports in your Linux system, run the following command (which should take a long time to complete).

$ sudo nmap -n -PN -sT -sU -p- localhost

4. Using lsof Command

The final tool we will cover for querying open ports is lsof command, which is used to list open files in Linux. Since everything is a file in Unix/Linux, an open file may be a stream or a network file.

To list all Internet and network files, use the -i option. Note that this command shows a mix of service names and numeric ports.

$ sudo lsof -i

List Open Network Files Using lsof Command

List Open Network Files Using lsof Command

To find which application is listening on a particular port, run lsof in this form.

$ sudo lsof -i :80

Find Application Using Port

Find Application Using Port

That’s all! In this article, we have explained four ways to check open ports in Linux. We also showed how to check which processes are bound upon particular ports. You can share your thoughts or ask any questions via the feedback form below.

Source

Leave a Reply

Your email address will not be published. Required fields are marked *

WP2Social Auto Publish Powered By : XYZScripts.com