Network security

How to Check Open Ports on Linux: ss, netstat, lsof and nmap

Every listening port is a door into your Linux machine. Here is how to list them, identify the process behind each one, and check what the internet can actually reach.

Cysoro Security TeamPublished · 9 min read
NETWORK SECURITY Open Ports on Linux List them, trace them, close the ones you do not need $ sudo ss -tulpn tcp LISTEN 0.0.0.0:22 tcp LISTEN 0.0.0.0:443 tcp LISTEN 0.0.0.0:3306 tcp LISTEN 0.0.0.0:6379 3306 and 6379 should not be public CYSORO.COM
Quick answer

To check open ports on Linux, run sudo ss -tulpn to list all listening TCP and UDP ports with the process behind each one. Use sudo lsof -i :PORT to find what owns a specific port, and run nmap from a second machine to see which ports are actually reachable through the firewall. Then close or restrict anything that should not be public.

Key takeaways

  • sudo ss -tulpn is the fastest way to list every listening port on a Linux system, with the owning process.
  • ss shows what is listening locally, but only nmap from another machine shows what the firewall actually exposes.
  • Every unexpected open port should be traced to a process, then closed at the service or the firewall.

Every program that accepts network connections opens a port, and every open port is a door into your machine. Checking which ports are open on Linux is one of the simplest security audits you can do — and one of the most revealing, because forgotten services and misconfigured apps show up immediately.

What does it mean for a port to be open on Linux?

A port is open, or listening, when a program on your machine is waiting for network connections on that port number. A web server listens on port 80 or 443, SSH listens on port 22, and a database might listen on port 3306 or 5432. If nothing is listening, the port is closed.

There is an important distinction between listening and reachable. A service can listen on all network interfaces, which means anyone who can reach the machine can try to connect, or it can listen only on localhost (127.0.0.1), which means only programs on the same machine can connect. The ss output shows this in the local address column: 0.0.0.0:8080 means all interfaces, while 127.0.0.1:8080 means local only.

A third layer sits in between: the firewall. A port can be listening and still unreachable from outside if the firewall drops the traffic. That is why a full audit needs both a local check and an external scan, as you will see below.

How do you check open ports with ss?

Use ss first: it is the modern default, it is preinstalled on current distributions, and it queries the kernel directly instead of parsing text, which makes it fast even on busy servers. Run sudo ss -tulpn to list every listening TCP and UDP socket with its process.

Each flag does one job: -t shows TCP sockets, -u shows UDP sockets, -l shows only listening sockets, -p shows the process name and PID, and -n shows numbers instead of guessing service names, so :3306 stays :3306. Run it with sudo: without root, sockets owned by other users show the port and state but no process name.

Reading ss -tulpn output Netid State Local Address:Port tcp LISTEN 0.0.0.0:22 tcp LISTEN 127.0.0.1:3306 Process sshd mysqld 0.0.0.0:22 — public SSH listens on every interface 127.0.0.1:3306 — local only MySQL accepts local connections only The address column tells you who can connect — read it before the port number.
How to read ss output: the local address shows whether a port is public or local-only. Illustration by Cysoro.

Useful variations cover most day-to-day needs. ss -tl shows only listening TCP ports, ss -ul shows only UDP, and ss -tulnp | grep ':22' finds one specific port. For a clean list you can save and compare later, run ss -tuln without the process column.

Watch for one special case: if ss shows systemd as the owner, the port is socket-activated. Systemd itself is listening and will start the real service on the first connection, so stopping the service alone will not close the port — you need to stop the socket unit too.

How do you check open ports with netstat?

Use netstat when ss is not available, usually on older systems where existing scripts and documentation still reference it. The command mirrors ss: run sudo netstat -tulnp to list listening TCP and UDP ports with their processes.

Netstat is part of the net-tools package, which is not installed by default on many modern distributions. On Debian and Ubuntu, install it with sudo apt install net-tools; on RHEL, CentOS and Fedora, use sudo dnf install net-tools. The output columns are the same as ss: protocol, local address, state and the process behind the socket.

Prefer ss on any current system. Netstat is officially deprecated in favor of ss, it is slower on systems with many connections, and it may disappear from future distributions. Learn the ss flags and you will not need it.

How do you find which process owns a port with lsof?

Use lsof once you already know the port and need to pin down exactly which application, user or process is using it. Run sudo lsof -i :8080, replacing 8080 with the port you are investigating, to see the command, PID, user and connection details.

Narrow the results when you need precision: sudo lsof -iTCP:8080 -sTCP:LISTEN restricts the output to TCP sockets on port 8080 that are actively listening. To list all listening ports in one go, run sudo lsof -nP -iTCP -sTCP:LISTEN, where -n and -P stop slow DNS and service-name lookups.

Once you have the PID, dig further with ps -o pid,user,cmd -p 1530 for the full command line and owner, or systemctl status 1530 to see which systemd service started it. A process named python3 or java tells you little on its own; the full command line usually reveals which application it really is.

How do you check ports from outside with nmap?

Use nmap to confirm a port is actually reachable over the network, which none of the local tools can tell you. The view from inside the server does not show what the firewall lets through, so scan from a second machine — your laptop or another server. Only scan systems you own or have explicit written permission to test.

Install nmap on the machine you scan from: sudo apt install nmap on Debian-based distributions, or sudo dnf install nmap on RHEL and Fedora. Then scan the target: nmap -Pn -p- 203.0.113.10 checks all 65,535 TCP ports, while nmap -p 22,80,443 203.0.113.10 checks just the ports you name. The -Pn flag skips host discovery, which is useful when the target blocks ping.

Nmap reports each port in one of four states, as documented in the official Nmap port scanning guide. Open means an application is listening and reachable. Closed means the port is reachable but nothing is listening. Filtered means a firewall or filter is blocking the probe, so nmap cannot tell whether the port is open or closed. Unfiltered means the port is reachable but nmap cannot determine its state.

Local view vs outside view From inside the server ss · netstat · lsof See every listening socket See the owning process Cannot see the firewall May overstate exposure From outside (nmap) Scan from a second machine See what the firewall allows See open / filtered / closed Cannot see the process Shows what attackers see A real audit needs both views — one tells you what listens, the other what is reachable.
Local tools show listening sockets; nmap shows what the network actually exposes. Illustration by Cysoro.

For a quick single check without nmap, run nc -vz 203.0.113.10 3306: it tells you whether one TCP port accepts connections. UDP scanning is slower and less certain, because a silent UDP port can be open or filtered — nmap reports it as open|filtered when it cannot tell. Use sudo nmap -sU --top-ports 50 203.0.113.10 for the most common UDP ports.

Which tool should you use for checking ports?

Each tool answers a different question, so the right choice depends on what you already know. Start with ss for the full local picture, use lsof to investigate one port, and finish with nmap from outside.

ToolBest forShows process?Shows firewall effect?Install needed?
ssFull local list of listening portsYes, with -pNoNo, preinstalled
netstatOlder systems without ssYes, with -pNoOften, net-tools
lsofFinding the owner of one portYesNoSometimes
nmapExternal, firewall-aware scanNoYesYes
ncQuick test of one portNoYesUsually preinstalled

If you only remember one command, make it sudo ss -tulpn. If you only remember one habit, make it checking from outside as well as inside. The nmap man page documents every scan type and option if you want to go deeper.

Which open ports are normal, and which are suspicious?

Some open ports are expected on a working server, and others should set off alarms. The table below covers the ports you will see most often, but the rule is simple: if you cannot name the service behind a port, investigate it.

PortUsual serviceShould it face the internet?
22SSHOnly if restricted or key-only
80 / 443HTTP / HTTPSYes, for a web server
53DNSOnly for a DNS server
3306MySQL / MariaDBNo — local only
5432PostgreSQLNo — local only
6379RedisNo — local only
3389Remote DesktopNo — use a VPN
8080 / 8443Web apps, proxiesOnly if intentional

Database ports are the classic mistake. MySQL, PostgreSQL and Redis are often installed with their default settings, listening on all interfaces with weak or no authentication, and exposed to the internet by accident. If a database does not need remote access, bind it to localhost. The same applies to management panels, message queues and anything with a default password.

High-numbered ports deserve attention too. A service listening on a random high port is often a development server, a container with a published port, or something installed by an attacker. Check Docker's published ports with docker ps when a port has no obvious owner — containers are a common source of surprise exposure.

How do you close ports you do not need?

Closing a port means stopping the thing that listens on it, or blocking access to it. Fix it at the source first, then add the firewall as a second layer — a firewall rule alone leaves the service running and one misconfiguration away from exposure.

  1. Identify the owner with sudo ss -tulpn or sudo lsof -i :PORT.
  2. Stop the service with sudo systemctl stop servicename, and disable it with sudo systemctl disable servicename if it should not come back after a reboot.
  3. Or bind it to localhost if the service is needed locally but not remotely — edit its configuration to listen on 127.0.0.1 only.
  4. Block it at the firewall as a second layer, with ufw or firewalld, so even a restarted service is not exposed.
  5. Verify the fix by running ss again and rescanning from outside with nmap.

For SSH, which many servers do need exposed, reduce the risk instead of closing it: use key-only authentication, disable password login, restrict access to known addresses where possible, and install fail2ban to block brute-force attempts. Our guide to securing your Wi-Fi and home network applies the same least-exposure thinking to the network around the server.

How do you keep track of open ports over time?

An audit is only accurate on the day you do it. Services get installed, containers get published, and configuration drifts. Keep a baseline of your listening ports and compare it regularly, so a new port stands out instead of blending in.

Save a baseline with ss -tuln | sort > ports-baseline.txt, then repeat the command later and compare the two files with diff. Any port in the new file that is not in the baseline needs an explanation. Automate the check with a scheduled job if the server matters, and alert on changes rather than waiting for a manual review.

Repeat the external nmap scan on the same schedule. Internal and external views drift apart over time: a firewall rule changed for troubleshooting, a service restarted with different settings, or a new application opening a port you did not expect. The external scan is the one that shows what an attacker can actually reach, so treat it as the authoritative view. For a broader security review of the services behind those ports, run your domain through our free security headers checker.

The bottom line

Checking open ports on Linux takes two minutes: sudo ss -tulpn for the local picture, lsof to identify anything unfamiliar, and nmap from a second machine to see what the firewall really exposes. Do it on every server you run, and repeat it whenever software changes.

Every port you cannot explain is a question, not a detail. Trace it to a process, decide whether it needs to be reachable, and close it if it does not. Check what your own systems expose with our IP lookup tool as a starting point for the audit.

Frequently asked questions

What is the fastest way to check open ports on Linux?

Run sudo ss -tulpn. It lists every listening TCP and UDP socket with the port number, the address it is bound to, and the process that owns it. It is part of iproute2 and is installed on virtually every modern distribution.

What does ss -tulpn mean?

Each flag adds one piece of information: -t shows TCP sockets, -u shows UDP sockets, -l shows only listening sockets, -p shows the process name and PID, and -n shows numeric ports instead of service names. Together they give the fullest useful picture in one command.

How do I check if a specific port is open on Linux?

Run sudo ss -tulnp | grep ':8080' with your port number, or sudo lsof -i :8080 to see the exact process. To test from outside the machine, run nc -vz hostname 8080 or nmap -p 8080 hostname from another computer.

What is the difference between ss and netstat?

ss is the modern replacement for netstat. It reads socket data directly from the kernel, so it is faster and more detailed, especially on busy systems. netstat is deprecated on most distributions but still works on older systems and in older scripts.

Is it safe to run nmap on my own server?

Yes, scanning systems you own or administer is normal security work. Only scan systems you own or have explicit written permission to test. Scanning someone else's systems without permission can be illegal and can trigger their security monitoring.

Why does ss show a port that nmap says is closed?

Because ss shows what is listening on the machine, while nmap shows what is reachable through the network and firewall. A service can listen on all interfaces and still be blocked by the firewall, or it can listen only on localhost, which is not reachable from outside at all.

How do I close an open port on Linux?

Stop or disable the service that owns it, or bind it to localhost only if it does not need remote access. Then verify with ss that the port is gone, and check the firewall rules so the port is not accidentally reopened later.

Which ports should never be open to the internet?

Database ports such as MySQL 3306, PostgreSQL 5432 and Redis 6379, remote desktop port 3389, and management interfaces should never face the internet. SSH port 22 should be restricted to known addresses or protected with key-only authentication and fail2ban.

Sources

  1. Nmap — Port Scanning Techniques (Nmap Reference Guide)
  2. Nmap — nmap(1) man page
  3. PhoenixNAP — How to Check Open Ports in Linux
  4. Atera — How to check the list of open ports in Linux
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against the official Nmap reference guide and man pages, and the ss, netstat, lsof and nmap command documentation.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free