Back to commands

Cybersecurity Triage

Read-only

Find Listening Ports with ss

You need to list local TCP services that are accepting connections.

Command

ss -ltnp

Before you run this

System impact: Read-only. Low when scoped to the shown target.

When not to use it: Do not assume a listening socket is externally reachable; firewall and bind address still matter.

Expected output

Listening TCP sockets with bind address, port, and process details when permissions allow. Use LISTEN rows for port-conflict questions; ESTABLISHED rows are active sessions and do not prove a service is accepting new connections.

System impact

Read-only. Nothing changes. The command displays listening TCP sockets.

Recovery / rollback: no state is changed.

When to use it

Use when a service should be reachable, or when you need to audit listening ports.

When not to use it

Do not assume a listening socket is externally reachable; firewall and bind address still matter.

Common misread

Do not kill the first process you see. Check whether the row is LISTEN, whether the bind address is localhost or public, and whether a supervisor such as systemd or Docker owns the process.

LISTEN vs ESTABLISHED

Use LISTEN rows for service reachability and port-conflict questions. Use ESTABLISHED rows when you are investigating active client sessions.

  1. ss -ltnp
  2. ss -tan state established

PID and program interpretation

The PID/program field tells you who owns the socket. If the owner is hidden, rerun with sudo. If the owner is systemd, Docker, or a process manager, inspect that owner before killing the PID.

  1. sudo ss -ltnp
  2. ps -fp 4242
  3. systemctl status nginx --no-pager --lines=30

Systemd and container context

A listener may be restarted by systemd or published by Docker. Check service status and container port mappings before moving ports or stopping processes.

  1. systemctl status nginx --no-pager --lines=30
  2. docker ps --format 'table {{.Names}}\t{{.Ports}}'

next steps

Related commands

Cybersecurity Triage Sensitive output

Find Allowed Ports with No Listener

An open firewall rule can outlive the service it was created for.

comm -23 <(ufw status numbered | awk '/ALLOW/ {print}' | grep -Eo '[0-9]+/(tcp|udp)' | cut -d/ -f1 | sort -u) <(ss -ltnp | awk '/LISTEN/ {n=split($4,a,":"); print a[n]}' | sort -u)
Cybersecurity Triage Sensitive output

Find Public Listeners Not Allowed by UFW

The process was public, but the firewall did not mention it.

comm -13 <(ufw status numbered | awk '/ALLOW/ {print}' | grep -Eo '[0-9]+/(tcp|udp)' | cut -d/ -f1 | sort -u) <(ss -ltnp | awk '$4 ~ /^(0[.]0[.]0[.]0|[[]::[]]|[*]):/ {n=split($4,a,":"); print a[n]}' | sort -u)

next diagnostic step

Where to go from this command

Study mapping

Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.

  • LPIC-1 style command-line practice
  • LFCS style performance-task practice
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.