Skip to content
Latchkey

netstat Command Reference: Flags, Usage & CI Examples

netstat lists network connections, listening sockets, and routes.

netstat reports sockets, listening ports, and routing on a host. It is the classic tool for "is anything listening on this port", though ss is the modern, faster replacement.

Common flags and usage

  • -t / -u: TCP / UDP sockets
  • -l: listening sockets only
  • -n: numeric addresses and ports (no DNS)
  • -p: show the owning process (needs privilege)
  • -a: all sockets, listening and established
  • -r: routing table

Example

shell
netstat -tlnp | grep ':5432' || echo "postgres not listening yet"

In CI

netstat -tlnp is a quick way to confirm a service bound its port inside a runner. It lives in net-tools, which slim images often omit; prefer ss (from iproute2) where available, since netstat is deprecated on many distros.

Key takeaways

  • netstat -tlnp lists listening TCP ports and their processes.
  • It comes from net-tools, often absent on slim images.
  • ss is the modern, faster replacement.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →