Low Orbit Flux Logo 2 F

Linux - How to Check if a Port Is Open

One common thing that people come across when working on Linux systems ( or any other OS is how to tell if a port is open and listening.

To tell if a port is open on linux you can use the following command:

sudo netstat -tunlp

The above command should give you everything you need. It shows TCP and UDP ports that are listening. It will also show the associated PID for each port so you can find out which process is listening on that port. Here is a quick explanation of the options that we used:

-t TCP
-u UDP
-n Numeric, no host or port lookup
-l Listening
-p Show PID for associated process

Check out our netstat cheat sheet here for more info: Netstat Cheat Sheet.

Keep in mind that you may or may not have netstat installed on your system. If you don’t you can either install it or use an alternative command ( see below ).

SS Command

The ss command is a modern replacement for netstat. Depending on your distro you may have either netstat, ss, neither, or both. It can be run with similar parameters to what you would use with netstat.

sudo ss -tunlp

Use lsof to Check If a Port is Open on Linux

Another tool that you can use is lsof. This stands for list open files. If you want to find all listening ports you can use this command:

sudo lsof -i -P -n | grep LISTEN

If you want to see what is listening on a specific port ( 8080 for example ) you can use the same command but with these options.

sudo lsof -i:8080

The above command will tell you what is listening on port 8080.

Fuser Command

The fuser command can be used to tell you what is using a given file. It can also be used to find out what is listening on a given port. To find out what is using port 8080, you can use the following:

fuser 8080/tcp

Using Nmap

Nmap is an excellent tool for network scanning and network exploration.

You can use nmap to scan for open ports like this:

sudo nmap -sTU -O

This is assuming your IP is