Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ss Command Guide for Inspecting Network Sockets

ss (“socket statistics”) shows which connections your machine has open, which ports it listens on, and how much traffic each one is moving — the modern replacement for netstat.


What is ss, and Why Use It?

ss investigates the network layer inside Linux. Every program that talks over the network — browsers, servers, SSH sessions — does so through a socket, and ss lists every socket the kernel knows about: connections in progress, ports waiting for clients, and statistics for each one.

It answers the two questions network debugging starts with:

  1. What is connected right now? — every TCP and UDP socket, with remote addresses and states.
  2. What is my machine offering? — the listening ports, and which process owns each one.

ss ships in the iproute2 package on every major distribution and is the actively maintained successor to netstat — faster, richer in output, and aware of more modern socket information.

Why Learn ss?

  • It shows you what your machine is doing on the network — invisible otherwise, and the first place to look when something “is using my port”.
  • Security work starts here — an unknown listening port is the classic sign of trouble; ss -tulpn finds it in one command.
  • netstat is deprecated — tutorials and distro documentation increasingly use ss, and it reports things netstat cannot (like socket memory usage).

ss needs no setup and reads kernel state directly — it is instant even on busy servers with thousands of connections, where older tools crawl.


1. Seeing All Connections

The default invocation lists every socket:

ss
Netid  State   Recv-Q  Send-Q  Local Address:Port  Peer Address:Port  Process
tcp    ESTAB   0       0       192.168.1.20:52144  93.184.216.34:443
tcp    LISTEN  0       128     0.0.0.0:22          0.0.0.0:*
udp    UNCONN  0       0       0.0.0.0:68          0.0.0.0:*

Each row is one socket: its type (tcp/udp), state, queue sizes, local and remote addresses, and — when run with the right flags — the process that owns it. The default view is compact but hides processes; the useful flags are next.

2. The Flags You Will Actually Use

ss is flag-driven. These four cover almost everything:

ss -t          # TCP connections only
ss -u          # UDP only
ss -l          # listening sockets only (ports your machine is offering)
ss -a          # everything — listening and connected

Combining them gives the classic views:

ss -t -a                    # all TCP sockets, listening and established
ss -u -a                    # all UDP sockets

Shorthand combining flags is common: ss -tlu means TCP, listening, UDP-ish filtering in one token.

3. The Power Flags: Processes and Numbers

To turn a socket list into something actionable, add these:

ss -tulpn
Netid  State   Recv-Q  Send-Q  Local Address:Port  Peer Address:Port  Process
tcp    LISTEN  0       128     0.0.0.0:22          0.0.0.0:*          users:(("sshd",pid=541,fd=3))
tcp    LISTEN  0       128     127.0.0.1:631       0.0.0.0:*          users:(("cupsd",pid=812,fd=7))

What each letter adds:

  • -t — TCP sockets.
  • -u — UDP sockets.
  • -l — listening sockets only.
  • -p — the process using each socket (name, PID, file descriptor) — needs root to see other users’ processes.
  • -n — numeric addresses and ports, skipping slow DNS lookups.

ss -tulpn — “all listening TCP and UDP ports, with owning process, numerically” — is the command for “what is running on this machine’s network”.

4. Filtering by Address, Port, or State

Real debugging narrows the list:

ss -t state established              # only connections currently ESTABLISHED
ss -t sport = :443                   # sockets whose source port is 443
ss -t dport = :22                    # sockets whose destination port is 22
ss src 192.168.1.20                  # sockets involving a specific address

Filters combine with and / or:

ss -t state established '( dport = :443 or dport = :80 )'

This finds every HTTPS and HTTP connection the machine currently has — useful when a browser or server misbehaves and you want to see its live conversations.

5. Statistics and Monitoring

ss also reports aggregate information:

ss -s
Total: 312  (kernel 0)
TCP:   47  (estab 12, closed 3, orphaned 0, timewait 8)
UDP:   6

ss -s prints a summary: how many sockets of each type, how many established, how many stuck in TIME-WAIT. A growing TIME-WAIT count or thousands of orphaned sockets is a symptom worth chasing.

For live monitoring, ss works with watch:

watch -n 1 'ss -t state established | head -20'

(See watch for the pattern.) This gives you a one-second-refresh view of active connections — the fastest way to spot a program opening sockets it should not.


Common Pitfalls

  • Forgetting -n — without it, ss tries to resolve every remote address through DNS, which makes the command slow and shows hostnames instead of the addresses you need to debug.
  • Not running as root for -p — process information for other users’ sockets is hidden from ordinary users; ss -tulpn without sudo shows blanks in the Process column.
  • Assuming LISTEN means exposed — a socket listening on 127.0.0.1 is reachable only from the machine itself; 0.0.0.0 or a public address means the whole network (or internet).
  • Confusing ss states with problems — TIME-WAIT and CLOSE-WAIT entries are normal parts of TCP; only sustained growth or unexpected states indicate trouble.
PageRelationship
netstatThe older tool ss replaces — same job, fewer features
ipShows the interfaces and addresses these sockets ride on
ncOpens raw connections to test the ports ss lists
tracerouteTraces the path when a remote address is unreachable

ss Cheatsheet

CommandWhat it does
ssList all sockets
ss -t -aAll TCP sockets
ss -tulnAll listening TCP/UDP ports, numeric
ss -tulpnListening ports with owning process (run as root)
ss -sSummary statistics of all sockets
ss -t state establishedOnly currently established TCP connections
ss -t dport = :443Sockets talking to port 443
ss src 192.168.1.20Sockets involving a specific address
watch -n 1 'ss -tn'Refresh the socket list every second