How to List Open Ports on Linux: ss, netstat, lsof and nmap Compared
Five commands that show open ports on any Linux distribution, what each is best at, how to read the output, and how to test a port from Windows.
3 min readBy Shailabh
Reviewed by the AmazingRDP technical team

Run a server of your own and decide which ports it shows. A Linux VPS gives you root access. See Linux VPS from $6.99
An open port is a door: a program on the machine is waiting for connections there. Knowing which doors are open is the first step of securing any server, and the first step of finding out why a service cannot be reached. Linux has several commands for it. They answer slightly different questions.
This page is the command reference for every distribution. For the Ubuntu routine with its firewall, see how to check open ports on Ubuntu.
Which command for which question
| Question | Command | Run it |
|---|---|---|
| What is listening on this machine? | ss | On the machine |
| Which program holds port 8080? | lsof or ss -p | On the machine |
| I only know the old command | netstat | On the machine |
| What can the outside world reach? | nmap | From another machine |
| Is this one port reachable? | nc | From another machine |
1. ss
sudo ss -tulpn
The standard tool on every current distribution. The letters: t TCP, u UDP, l listening only, p show the program, n numbers in place of names. sudo is needed to see the programs of other users.
The column that matters most is Local Address:Port:
| Shown | Meaning |
|---|---|
0.0.0.0:22 or *:22 | Listening on every network address: reachable from outside, unless a firewall blocks it |
[::]:22 | The same for IPv6 |
127.0.0.1:3306 | Listening for the machine itself only: not reachable from outside |
10.0.0.5:5432 | Listening on that one address only |
Filters:
sudo ss -tlpn 'sport = :443'
sudo ss -tulpn | grep nginx
2. lsof
sudo lsof -i :8080
sudo lsof -i -P -n | grep LISTEN
lsof lists open files, and a network connection counts as one. The first line answers "who has port 8080?" with program name, process number and user. That is what you need when a service refuses to start with "address already in use".
3. netstat
sudo netstat -tulpn
The predecessor of ss, with the same letters. It is no longer installed by default on most systems; it is in the package net-tools. There is no reason to install it on a new server.
4. nmap, from another machine
nmap 203.0.113.10
nmap -p 22,80,443,3306 203.0.113.10
sudo nmap -sU -p 53,123 203.0.113.10
The commands above show what is listening. Only a scan from outside shows what actually gets through the firewall and the provider's network. nmap reports each port as open, closed (reachable, nothing listening) or filtered (a firewall swallowed the packet). The third line scans UDP ports, which is slow and needs sudo.
Scan only your own machines. More tools in network and IP scanner tools compared.
5. nc, for a single port
nc -zv 203.0.113.10 443
A quick yes or no for one port. -z connects without sending anything; -v prints the result.
The same test from Windows
Test-NetConnection 203.0.113.10 -Port 22
PowerShell's built-in test. TcpTestSucceeded : True means the port is reachable from that PC. See also enable a port through PowerShell.
Listening is not the same as reachable
Between a listening program and the internet stands the firewall. Check what it allows:
| System | Command |
|---|---|
| Ubuntu, Debian with ufw | sudo ufw status |
| Fedora, RHEL, AlmaLinux, Rocky | sudo firewall-cmd --list-all |
| Any, the rules underneath | sudo nft list ruleset |
On the Red Hat family, SELinux adds one more gate: a service may only listen on ports its type is allowed to use. sudo semanage port -l | grep http shows them. A web server moved to an unusual port fails for that reason, with a firewall that looks correct.
What to do with the result
- A port you do not recognise: find the program with
lsof, then decide whether it should run at all. - A database on 0.0.0.0: bind it to 127.0.0.1 unless other machines must reach it, and then allow only their addresses.
- SSH and remote desktop ports: allow them for your own addresses where you can. See open or block a port in the Ubuntu firewall.
- Repeat after every installation. New software opens ports without asking.
Our Linux VPS plans give you root access to run all of this. Related: monitor network traffic in Windows.
Questions
How do I list open ports on Linux?
Run sudo ss -tulpn. It shows every listening TCP and UDP port with the program behind it.
How do I find which process is using a port?
Run sudo lsof -i :PORT with the port number.
What is the difference between ss and netstat?
ss is the current tool and installed everywhere. netstat is its older predecessor from the net-tools package.
How do I check whether a port is open from outside?
Scan it from another machine with nmap or test it with nc -zv host port.