You can check open ports on Linux with one command, ss -tulpn. It lists every port that is waiting for connections, the address it listens on and the program behind it. This guide shows that command, two others that confirm it, and how to read the result so you know which ports the internet can reach.

Everything below was run on Ubuntu 24.04 in our lab in November 2026. The outputs are real and trimmed to three test listeners we started for this guide.

The short answer

  • sudo ss -tulpn shows listening TCP and UDP ports with the owning process.
  • A port bound to 0.0.0.0, * or [::] accepts connections from other machines. A port bound to 127.0.0.1 or [::1] only answers on the server itself.
  • sudo lsof -i -P -n gives a second view of the same thing.
  • nmap run from another machine shows what gets through your firewall, and that is the view an attacker has.

Check open ports on Linux with ss

ss is part of the iproute2 package and is installed on every current distribution. It replaced netstat.

sudo ss -tulpn

The flags: -t TCP, -u UDP, -l listening sockets only, -p show the process, -n print numbers and skip name lookups. Without sudo you see the ports and miss the process names of other users.

Netid State  Recv-Q Send-Q Local Address:Port  Peer Address:Port Process
udp   UNCONN 0      0            0.0.0.0:5353       0.0.0.0:*     users:(("python3",pid=1136,fd=3))
tcp   LISTEN 0      128        127.0.0.1:6379       0.0.0.0:*     users:(("python3",pid=1134,fd=3))
tcp   LISTEN 0      5            0.0.0.0:8080       0.0.0.0:*     users:(("python3",pid=1132,fd=3))

Read the “Local Address:Port” column first. It tells you who can connect.

Local addressWho can connect
0.0.0.0 or *Any machine that can reach the server over IPv4
[::]Any machine over IPv6, and on most systems IPv4 as well
127.0.0.1 or [::1]Only programs on the server itself
A specific IP, such as 10.0.0.5Only machines that can reach that interface

In our output, port 8080 is open to the network and port 6379 is local only. A database or cache should look like the 6379 line. If MySQL (3306), Redis (6379), MongoDB (27017) or PostgreSQL (5432) shows 0.0.0.0, fix the bind address in its config before you do anything else.

For a quick list of addresses and ports only:

ss -tlnH | awk '{print $4}' | sort -u

Find the program behind a port

The process column gives you a name and a PID. To see the full command and when it started:

ps -o pid,user,lstart,cmd -p 1132
  PID USER                      STARTED CMD
 1132 root     Fri Nov 13 16:05:14 2026 python3 -m http.server 8080

To see the real binary, which matters when a process has been given a harmless-looking name:

sudo ls -l /proc/1132/exe
lrwxrwxrwx 1 root root 0 Nov 13 16:05 /proc/1132/exe -> /usr/local/bin/python3.13

A second view with lsof

sudo lsof -i -P -n | grep LISTEN
python3   1132 root    3u  IPv4   2906      0t0  TCP *:8080 (LISTEN)
python3   1134 root    3u  IPv4   3414      0t0  TCP 127.0.0.1:6379 (LISTEN)

lsof writes *:8080 where ss writes 0.0.0.0:8080. Both mean every interface. If the two tools disagree about which ports are open, treat the server as suspect and work through our guide on who logged in to your Linux server.

Scan the server with nmap

ss and lsof ask the server what it is listening on. nmap connects to the ports and reports which ones answer.

nmap -sT -p- 127.0.0.1
Not shown: 65529 closed tcp ports (conn-refused)
PORT      STATE SERVICE
6379/tcp  open  redis
8080/tcp  open  http-proxy

Two things to notice. Scanned from the server itself, the local-only port 6379 shows as open, because 127.0.0.1 is exactly where it listens. And nmap calls it “redis” although our listener was a Python test script. Without -sV, the service name is a lookup of the port number and proves nothing about what is running.

The scan that matters is the one from outside, against the public IP:

nmap -sT -p- 203.0.113.10

Run it from a machine on another network, for example your laptop on mobile data. Replace the address with your own. A port that ss shows on 0.0.0.0 and the outside scan shows as “filtered” or does not list is being blocked by a firewall or by your cloud provider’s security group. A port that both show as open is reachable by everyone.

Only scan systems you own or have written permission to test. More scan types are in our guide to Nmap scans for network admins.

Nmap Admin Pack, ₹49: a 2-page printable cheat sheet, a weekly scan script that reports only what changed, and a findings tracker spreadsheet. See the pack.

What to do with each open port

  1. Do not recognise the program? Find it with the ps and /proc commands above before you close anything.
  2. Not needed? Stop and disable the service: sudo systemctl disable --now servicename.
  3. Needed only by the server itself? Bind it to 127.0.0.1 in the service’s own config file and restart it.
  4. Needed by a few known machines? Allow only their addresses in the firewall or security group.
  5. Needed by everyone, such as 80 and 443? Keep the software patched and check the list again after every deployment.

SSH usually has to stay reachable. Our SSH hardening checklist for Ubuntu 24.04 covers keys, root login and rate limits.

Common questions

Is netstat still usable?

Yes, if the net-tools package is installed. netstat -tulpn prints almost the same columns. New servers often do not have it, so learn ss.

Why does ss show a port that nmap from outside does not?

A firewall or security group sits in between. That is the result you want for anything that is not public.

How often should I check?

After every install or deployment, and on a schedule. A new package can start a network service without asking.

Free tool: our website safety check looks at your site from the outside and grades its HTTPS, certificate and security headers in about 30 seconds.

Related guides

Sources

Want an outside view of your whole network? Our VAPT services scan and test your servers the way an attacker would and give you a prioritised fix list. Contact us for a quote.

Post author avatar

Bhaskar Soni

Bhaskar Soni is a Security Engineer and the founder of Youngster Company, based in Ahmedabad, Gujarat. He works hands-on with Linux server hardening, vulnerability assessment and penetration testing (VAPT), ISO 27001 compliance and OSINT investigations. He writes practical, tested guides for IT professionals and Indian businesses, and every article on this site is written or reviewed by him.

Leave a Reply