AI Hints
Home›Linux Tutorial›Watching the System
Linux · Lesson 97 of 120

Ports and Listening

Ss -tlnp.

⏱ 2 min read▶ Video at 2:09:51🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

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.

Ports and Listening
From the video: Ports and Listening
  • 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.

Terminal
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.

Terminal
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.

keyvalue
0.0.0.0:22anyone can connect
127.0.0.1:5432this computer only
[::]:22the same, for IPv6
ss -tlnpwhich 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
Next up: System Information — memory, disk, and uptime