When an alert wakes you up, you rarely think "I need lsof". You think "why is port 443 not answering?" or "which process is writing this file?". Cheat sheets organised by tool make you translate the question into a command under stress. This one is organised the other way round.

It assumes a systemd-based distribution (Ubuntu 22.04 or 24.04, RHEL 9 and derivatives). For a first-five-minutes triage routine and a deep dive on vmstat/iostat/pidstat, see our earlier posts; this page is the reference you keep open afterwards.

"Is the service listening, and on what?"

sudo ss -tlnp                   # TCP listening sockets, numeric, with process
sudo ss -ulnp                   # same for UDP
sudo ss -tlnp 'sport = :443'    # only port 443

Look at the local address column. 127.0.0.1:8080 means only local clients can connect; 0.0.0.0:8080 or [::]:8080 means all interfaces. A service bound to localhost behind a proxy is correct; one bound to localhost that should be public is your bug.

For listening sockets, Recv-Q is the number of connections waiting to be accepted and Send-Q is the backlog limit. Recv-Q sitting near Send-Q means the application is not calling accept() fast enough.

ss -s                                     # totals per state
ss -tn state established '( dport = :5432 )' | wc -l   # connections to Postgres
ss -tn state time-wait | wc -l            # TIME-WAIT count

"Who has this port or file open?"

sudo lsof -nP -iTCP:443 -sTCP:LISTEN   # who listens on 443
sudo lsof -nP -i @203.0.113.10         # connections to one host
sudo lsof /var/log/app/app.log         # who holds this file
sudo lsof -p 2231 | wc -l              # open files of one process
sudo lsof +L1                          # deleted files still held open

-n and -P skip DNS and port-name lookups, which otherwise make lsof slow exactly when DNS is the broken thing. +L1 lists files with link count zero: deleted from the directory but still consuming space because a process has them open. That explains a df that says full and a du that cannot find the space.

If lsof is not installed, /proc has the same data:

sudo ls -l /proc/2231/fd | wc -l
sudo fuser -v 443/tcp

"What did the service log?"

journalctl -u nginx --since "15 min ago"          # one unit, recent
journalctl -u nginx -p warning --since today       # warnings and worse
journalctl -u app -f                               # follow live
journalctl -u app -b -1                            # previous boot
journalctl -u app -o cat --no-pager | tail -100    # message text only
journalctl _PID=2231                               # one process
journalctl --since "2026-12-28 02:10" --until "2026-12-28 02:25"

-p takes a syslog priority and shows that level and more severe. -b -1 is the previous boot, which is what you want after an unexpected reboot. If journalctl -b -1 says there is no previous boot, the journal is not persistent; /var/log/journal must exist for logs to survive reboots.

To see why a unit failed, combine status and logs:

systemctl status app --no-pager -l
systemctl list-units --failed

"Where did the disk space go?"

df -hT                    # space per filesystem, with type
df -i                     # inodes; "No space left" with free bytes means inodes
sudo du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -15
sudo du -xh --max-depth=1 /var | sort -h | tail

-x keeps du on one filesystem, so it does not wander into /proc or network mounts. Walk down one level at a time; it is faster than one big scan. Common culprits worth checking directly: /var/log, /var/log/journal, /var/lib/docker, /var/lib/containerd, /tmp, and core dumps under /var/lib/systemd/coredump.

"What is the kernel saying?"

sudo dmesg -T --level=err,warn | tail -50     # human timestamps, errors only
journalctl -k -b --since "1 hour ago"          # kernel log via journal
journalctl -k | grep -i -E 'oom|killed process' # OOM killer

The kernel log is where you find the OOM killer's victims, disk and filesystem errors (I/O error, EXT4-fs error), network driver resets, hung task warnings, and segfaults (segfault at ... ip ... error). Check it early: an application error that "makes no sense" often has a kernel line right next to it in time.

"What is this process doing right now?"

sudo strace -f -tt -p 2231                     # attach, follow threads, timestamps
sudo strace -f -tt -e trace=network -p 2231    # only network syscalls
sudo strace -f -e trace=openat,read -p 2231    # file access
sudo strace -c -f -p 2231                      # summary table; Ctrl+C to print

strace answers "is it stuck, and on what?". A process blocked in futex is waiting on a lock in user space; in poll or epoll_wait, waiting for network input; in read on a socket, waiting for a peer; in connect, waiting for a TCP handshake that never completes. -c shows which syscalls take the time.

strace slows the traced process significantly. Attach briefly, never leave it running on a busy production process, and detach with Ctrl+C. For lower overhead, perf trace or eBPF tools do similar jobs.

Other quick looks at a process:

cat /proc/2231/status | grep -E 'State|Threads|VmRSS'
sudo cat /proc/2231/stack       # kernel stack if stuck in D state
sudo ls -l /proc/2231/cwd       # its working directory
sudo cat /proc/2231/environ | tr '\0' '\n'   # its environment

"Where is the request slow?"

curl -w breaks one request into phases without any extra tooling:

curl -s -o /dev/null -w '
dns      %{time_namelookup}
connect  %{time_connect}
tls      %{time_appconnect}
ttfb     %{time_starttransfer}
total    %{time_total}
code     %{http_code}
remote   %{remote_ip}
' https://api.example.com/health

Each value is cumulative seconds from the start. Large dns means resolver trouble; a jump between dns and connect is network latency or a SYN not answered; between connect and tls is the TLS handshake; between tls and ttfb is the server thinking. Compare against a request to the backend directly with --resolve api.example.com:443:10.0.3.14 to bypass DNS and load balancers.

Related checks:

dig +short api.example.com              # what DNS returns
resolvectl query api.example.com        # what systemd-resolved returns
ip route get 203.0.113.10               # which interface and gateway
openssl s_client -connect api.example.com:443 -servername api.example.com </dev/null 2>/dev/null | openssl x509 -noout -dates

The last line prints the certificate's validity dates, which answers "did the certificate expire?" in one command.

"Who is logged in and what changed?"

who -a; last -n 20               # sessions and recent logins
journalctl -u ssh -u sshd --since today   # SSH logins (unit name differs by distro)
ls -lt /etc | head               # recently changed config
rpm -qa --last | head            # recent package installs (RHEL)
grep " install \| upgrade " /var/log/dpkg.log | tail   # recent packages (Ubuntu)

Many incidents start with a change. Checking recent logins, package upgrades and configuration edits takes a minute and often ends the investigation.

Quick reference

Question

First command

Is it listening?

ss -tlnp

Who holds this port/file?

lsof -nP -i :PORT / lsof FILE

Space used by deleted files?

lsof +L1

What did it log?

journalctl -u UNIT --since "15 min ago"

Why did it fail?

systemctl status UNIT -l

Where is the disk?

df -hT, df -i, du -xh --max-depth=1

Kernel trouble?

dmesg -T --level=err,warn

Is it stuck?

strace -f -tt -p PID

Which phase is slow?

curl -w timing

What changed?

last, package logs, ls -lt /etc

Common mistakes

Mistake

Why it hurts

Do this instead

Running lsof without -nP

Hangs on DNS lookups

Always add -nP

du from / without -x

Scans network mounts and /proc

Use -x and walk one level

Leaving strace attached

Slows production traffic

Attach briefly, prefer -c

Grepping /var/log/syslog only

Misses journal-only units

Use journalctl -u

Testing through the load balancer only

Hides which hop is slow

Add --resolve to hit backends

Key takeaways

  • Start from the question; each one maps to one or two commands with specific flags.

  • ss and lsof -nP answer socket questions; lsof +L1 explains invisible disk usage.

  • journalctl -u ... --since and dmesg -T --level=err,warn cover most "what happened".

  • strace shows where a process is stuck, but attach briefly.

  • curl -w splits a slow request into DNS, connect, TLS and server time.

References