Linux Command Reference ยท Networking
Linux ss command
Reference for the Linux ss command: list listening ports, established connections and the processes behind them, with filters and the replacement for netstat.
ss (socket statistics) lists the sockets the kernel knows about: listening servers, established connections, UDP endpoints and Unix sockets. It reads directly from the kernel, so it is faster than netstat on busy servers, and it can filter by state, port and address.
The question it answers most often is "what is listening on this port, and which process owns it?"
ss -tulpn # listening TCP/UDP sockets with processes ss -tn state established ss -tn '( dport = :443 or sport = :443 )'
Try it
ss is not installed here, so its output is read-only. The kernel publishes the same data in /proc/net/tcp, with addresses and ports in hexadecimal. The runnable example decodes one such line the way ss does.
Read-only: typical output.
$ ss -tlnp State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=812,fd=3)) LISTEN 0 511 127.0.0.1:8080 0.0.0.0:* users:(("nginx",pid=905,fd=6))
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
ss [OPTIONS] [FILTER]
| Option | Description |
|---|---|
-t, -u, -x |
TCP, UDP, Unix sockets. |
-l |
Only listening sockets. |
-a |
All sockets, listening and not. |
-n |
Numeric ports and addresses (no name lookups; much faster). |
-p |
Show the owning process (needs root to see all). |
-4, -6 |
IPv4 or IPv6 only. |
-s |
Summary of socket counts. |
-o |
Show timers (keepalive, retransmit). |
-i |
Internal TCP details (RTT, congestion window). |
-e |
Extended: user ID, inode. |
-H |
No header line, handy for scripts. |
Filters combine a state and an expression: ss -t state established '( sport = :ssh )', ss dst 10.0.0.0/8, ss -tn dport = :5432.
Returns: 0 on success; non-zero on invalid options or filters.
Usage notes
- Remember
-tulpn: TCP, UDP, listening, process, numeric. Addsudoto see process names for other users' sockets. - Reading addresses:
0.0.0.0:80or*:80listens on all IPv4 interfaces;127.0.0.1:80accepts only local connections;[::]:80is the IPv6 wildcard (and often dual-stack). - Recv-Q and Send-Q mean different things by state: for LISTEN,
Recv-Qis the current accept queue andSend-Qthe backlog limit. For connections they are unread and unacknowledged bytes; large values mean a slow reader or network. - Counting connections by state:
ss -tan | awk 'NR>1 {c[$1]++} END {for (s in c) print s, c[s]}'. Many TIME-WAIT is normal; many CLOSE-WAIT usually means the application forgets to close sockets. - Port already in use?
ss -ltnp 'sport = :8080'names the process holding it. - Filters are case-sensitive keywords and the expression usually needs quoting because of the parentheses.
- Replaces
netstat(netstat -tulpnbecomesss -tulpn); output columns differ, so update scripts that parse them. - Unix sockets:
ss -xlshows local service sockets such as/run/docker.sock.