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
ss Command Reference: Flags, Usage & CI ExamplesReference for ss: -tlnp, -s, state filters, the netstat replacement role, and a CI example that confirms a se…
lsof Command Reference: Flags, Usage & CI ExamplesReference for lsof: -i, -P, -n, -p, -t, the port-and-file-owner use, and a CI example that finds which proces…
nc (netcat) Command Reference: Flags, Usage & CI ExamplesReference for nc/netcat: -z, -v, -w, -l, the port-probe pattern, and a CI example that waits for a TCP port t…