How to use netstat and ss for socket inspection
· Category: Linux
Short answer
ss and netstat display socket statistics, active connections, and listening ports.
Steps
- List all listening ports:
ss -tlnp
- Show active TCP connections:
ss -tunap
- Filter by port:
ss -tlnp sport = :80
- Legacy netstat:
netstat -tlnp
Tips
ssis faster thannetstatbecause it reads from kernel structures directly.-pshows the process using the socket (requires root for all processes).- Use
-4or-6to filter by IP version.
Common issues
- Missing process names: run with
sudoto see all processes. - Very high connection counts:
sshandles large numbers better thannetstat.