Ports and Listening
Ss -tlnp.
A server runs services, and each service waits for visitors on a port. Which ports are open on your computer? It's a question every Linux admin asks, especially for security.

- Services wait on ports
- Which ports are open?
- A security question
Who is listening?
First we start the SSH service. Then SS dash TLN lists listening ports. T for TCP, L for listening, N for numbers instead of names. The line with colon twenty two is SSH, waiting for logins. Zero dot zero dot zero dot zero means it accepts connections from anywhere.
sudo service ssh start * Starting OpenBSD Secure Shell server sshd ...done. ss -tln State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:*
Which program?
Add P, and with sudo, SS also shows which program owns each port. Here it's SSHD, the SSH server. If you ever find a port open that you don't recognise, this tells you exactly which program to look at.
sudo ss -tlnp State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=29,fd=3)) LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=29,fd=4))
Reading the address
The address column tells you who can connect. Zero dot zero dot zero dot zero, or a star, means any network. One two seven dot zero dot zero dot one means only this computer itself. A database listening only on localhost is safe. One listening on everything may not be.
| key | value |
|---|---|
| 0.0.0.0:22 | anyone can connect |
| 127.0.0.1:5432 | this computer only |
| [::]:22 | the same, for IPv6 |
| ss -tlnp | which program |
Summary
SS dash TLN lists listening ports, and adding P shows the program behind each one. Check the address to see who can connect. Next, checking the health of the system.
Key takeaways- ss -tln
- sudo ss -tlnp
- 0.0.0.0 vs 127.0.0.1