What's listening on each port? ss -ltnp and friends

The command I use most to understand a Linux server I don't know (or no longer remember). How to read it, Docker, Windows, and how to check from outside.

IvánPublished on Updated on October 10, 20264 minLeer en español

When I log into a server and want to know what’s running, the first command I type is this:

sudo ss -ltnp
  • l → only what’s listening.
  • t → TCP connections.
  • n → show port numbers instead of names (“22” instead of “ssh”).
  • p → which process owns each port (hence the sudo).

1. How to read the output

A chunk of what I get on the Raspberry Pi:

0.0.0.0:22       users:(("sshd",pid=775,fd=3))
0.0.0.0:3000     users:(("docker-proxy",pid=1376405,fd=8))
0.0.0.0:8080     users:(("python",pid=3793306,fd=4))
127.0.0.1:8222   users:(("docker-proxy",pid=1397652,fd=8))
127.0.0.1:631    users:(("cupsd",pid=3913005,fd=7))

The column that matters is the address:

Address Who can connect
0.0.0.0:port or [::]:port Anyone who can reach the machine (the whole home network)
127.0.0.1:port Only the machine itself
100.x.x.x:port Only via that interface (for example, Tailscale’s)

At a glance I can check, for example, that my password manager (8222) only listens locally, as intended. Same with n8n: it’s bound to 127.0.0.1:5678 and I reach it from outside through Tailscale. If I ever see 0.0.0.0:5678, I’ve broken something in the docker-compose.yml.

2. If it says docker-proxy

When the process is docker-proxy, the port belongs to a container. To find out which one:

docker ps --format '{{.Names}}\t{{.Ports}}'

That’s exactly the case with Portainer on my Pi: it runs outside compose, started with a standalone docker run. Its ports (8000 and 9443) show up as docker-proxy and don’t appear in any docker-compose.yml, so if you look for them there you won’t find them. docker ps tells you in a second.

3. When a service won’t start

The classic error is “address already in use”. Find out who has the port:

sudo ss -ltnp | grep :8080

Or, with ss’s own filter, which is more precise (it won’t confuse 8080 with 18080):

sudo ss -ltnp 'sport = :8080'

A real example: Gitea ships its own SSH server, and port 22 is already taken by the Pi’s sshd. That’s why SSH on my Gitea runs on 2222. Before picking a port for something new, this command tells you whether it’s free.

Other variants I use:

  • Active connections (not just listening): drop the l.

    ss -tnp
  • UDP too (DNS, WireGuard…): add u.

    sudo ss -ltunp
  • If ss isn’t there (old or minimal machines): sudo lsof -i :8080 or sudo fuser 8080/tcp do the same for a single port.

4. Checking from outside

ss tells you what happens inside the machine. But something listening on 0.0.0.0 doesn’t mean it’s reachable: there may be a firewall in the way. And the other way round, sometimes you want to check what a device you can’t log into exposes (a NAS, a printer).

For a single port, from another machine:

nc -zv 192.168.1.60 445

For several at once, nmap. My NAS, after I closed what I don’t use, should only expose SMB and its web panel. This is how I check:

nmap -p 22,139,445,873,2049,5000,5001 192.168.1.60

SMB (139, 445) and the panel (5000, 5001) should be open, and SSH (22), rsync (873) and NFS (2049) closed. If any of those three shows up open, someone has turned something on. And if you don’t even know the IP, you can sweep the network for a port only one device has. That’s how I found my 3D printer when it changed IP (I cover it in the DHCP reservation article):

nmap -p 1883 --open 192.168.1.0/24

Only scan your own network. On other people’s networks (or at work without permission) it’s not a good idea.

5. On Windows

The PowerShell equivalent:

Get-NetTCPConnection -State Listen | Sort-Object LocalPort |
  Select-Object LocalAddress, LocalPort, OwningProcess

To see the program name and not just its process ID:

Get-NetTCPConnection -State Listen |
  Select-Object LocalAddress, LocalPort,
    @{n='Process'; e={(Get-Process -Id $_.OwningProcess).ProcessName}}

And to test a remote port, Windows’ version of nc -zv is:

Test-NetConnection 192.168.1.60 -Port 445

Or the classic netstat -ano | findstr LISTENING, which gives you the process ID to look up in Task Manager.

What not to do

  • Assume a service is “local only” because that’s how you remember it. Check with ss.
  • Use a bare grep :80: it also matches 8080, 8000 and anything in the 3000s. The sport = :80 filter is better.
  • Think that 0.0.0.0 in ss guarantees you can reach it from outside. The firewall has the final say.
  • Scan networks that aren’t yours.

Summary

  1. sudo ss -ltnp to see what’s listening and who owns it.
  2. Look at the address: 0.0.0.0 is the whole network, 127.0.0.1 only the machine.
  3. If it says docker-proxy, docker ps tells you which container.
  4. To check from outside, nc -zv or nmap.
  5. On Windows, Get-NetTCPConnection and Test-NetConnection.

Docs and your notes can be out of date, but what’s listening on each port is the truth. It’s the fastest way to inventory a server, and to discover things you’ve left open without knowing.

Mini quiz

Did it stick?

Three quick questions. Each right answer is worth 10 XP.

  1. In ss -ltnp, what does the l stand for?
  2. If you see 127.0.0.1:8222, who can connect to that service?
  3. ss says a port is listening on 0.0.0.0, but another machine can't connect. What's most likely?
  • #linux
  • #networking
  • #ports
  • #commands
  • #docker
Esc