SS(8)

๐Ÿ’– ss(8) โ€” another utility to investigate sockets ๐Ÿ’–

okay bestie, sit down, grab a strawberry ๐Ÿ“, because we're about to get so cozy with ss(8) โ€” the System Manager's Manual's own certified socket-investigator icon. yes she lives in section 8 (that's the sysadmin section, iykyk ๐Ÿ‘‘). she's a utility to investigate sockets and she ate, no cap.


โœจ NAME โœจ

ss โ€” another utility to investigate sockets ๐Ÿฆ‹


โœจ SYNOPSIS โœจ

ss [options] [ FILTER ]

โœจ DESCRIPTION โœจ

ss is used to dump socket statistics. it lets you show information that's similar to netstat, which, love her, but. and get this โ€” she can display more TCP and state information than other tools do. it's giving main character energy fr fr ๐Ÿ’…


โœจ OPTIONS โœจ

okay so when you use no option at all, ss shows you a list of open non-listening sockets (that's your TCP/UNIX/UDP girlies and friends ๐Ÿ’œ) that have established connections. so if you just run her bare, that's the vibe you get.

  • -h, --help โ€” show a summary of the options. a lil cheat sheet, we love her ๐ŸŽ€
  • -V, --version โ€” output version information. who is she? what era is she from? find out โญ
  • -H, --no-header โ€” suppress the header line. bye bye header ๐Ÿ’€
  • -Q, --no-queues โ€” suppress the sending and receiving queue columns. the queues are on mute ๐Ÿ“ต
  • -O, --oneline โ€” print each socket's data on a single line. one socket, one line, minimal chaos ๐ŸŒธ
  • -n, --numeric โ€” don't try to resolve service names. and show exact bandwidth values instead of human-readable ones. no pretty rounding, just the raw digits ๐Ÿงš
  • -r, --resolve โ€” try to resolve numeric address/ports. the opposite energy of -n, she wants names ๐Ÿซถ
  • -a, --all โ€” display both listening and non-listening sockets. (for TCP, "non-listening" means established connections.) everybody's invited to this party ๐Ÿ”ฅ
  • -l, --listening โ€” display only listening sockets. and yes, these are omitted by default, so you need this flag if listening is what you're after ๐Ÿ‘‘
  • -B, --bound-inactive โ€” display only TCP sockets that are bound but inactive (not listening, not connecting, etc.). these are also omitted by default. the wallflowers get their moment ๐ŸŽ€
  • -o, --options โ€” show timer information. for the TCP protocol, the output format is:
timer:(<timer_name>,<expire_time>,<retrans>)
  • <timer_name> โ€” the name of the timer. there are five kinds of timer names:
    • on โ€” means one of these timers: TCP retrans timer, TCP early retrans timer and tail loss probe timer
    • keepalive โ€” tcp keep alive timer
    • timewait โ€” timewait stage timer
    • persist โ€” zero window probe timer
    • unknown โ€” none of the above timers ๐Ÿ™ˆ
  • <expire_time> โ€” how long until the timer will expire โณ
  • <retrans> โ€” how many times retransmissions have occurred ๐Ÿ”
  • -e, --extended โ€” show detailed socket information. the output format is:
uid:<uid_number> ino:<inode_number> sk:<cookie>
  • <uid_number> โ€” the user id the socket belongs to
  • <inode_number> โ€” the socket's inode number in VFS
  • <cookie> โ€” a uuid of the socket ๐Ÿช
  • -m, --memory โ€” show socket memory usage. the output format is:
skmem:(r<rmem_alloc>,rb<rcv_buf>,t<wmem_alloc>,tb<snd_buf>,
              f<fwd_alloc>,w<wmem_queued>,o<opt_mem>,
              bl<back_log>,d<sock_drop>)
  • <rmem_alloc> โ€” the memory allocated for receiving packets ๐Ÿ“ฅ
  • <rcv_buf> โ€” the total memory that can be allocated for receiving packets
  • <wmem_alloc> โ€” the memory used for sending packets (which has been sent to layer 3) ๐Ÿ“ค
  • <snd_buf> โ€” the total memory that can be allocated for sending packets
  • <fwd_alloc> โ€” the memory allocated by the socket as cache, but not used for receiving/sending packets yet. if memory is needed to send/receive packets, the memory in this cache gets used before allocating additional memory. she recycles, she's sustainable ๐ŸŒˆ
  • <wmem_queued> โ€” the memory allocated for sending packets (which has not been sent to layer 3)
  • <opt_mem> โ€” the memory used for storing socket options, e.g., the key for TCP MD5 signature ๐Ÿ”‘
  • <back_log> โ€” the memory used for the sk backlog queue. on a process context, if the process is receiving packets, and a new packet is received, it will be put into the sk backlog queue, so it can be received by the process immediately โšก
  • <sock_drop> โ€” the number of packets dropped before they are de-multiplexed into the socket ๐Ÿ’€
  • -p, --processes โ€” show processes using sockets. who's home ๐Ÿ 
  • -T, --threads โ€” show threads using sockets. and heads up, this implies -p ๐Ÿงต
  • -i, --info โ€” show internal TCP information. the below fields may appear:
    • ts โ€” show string "ts" if the timestamp option is set
    • sack โ€” show string "sack" if the sack option is set
    • ecn โ€” show string "ecn" if the explicit congestion notification option is set
    • ecnseen โ€” show string "ecnseen" if the saw ecn flag is found in received packets
    • fastopen โ€” show string "fastopen" if the fastopen option is set
    • cong_alg โ€” the congestion algorithm name. the default congestion algorithm is "cubic" ๐ŸงŠ
    • wscale:<snd_wscale>:<rcv_wscale> โ€” if window scale option is used, this field shows the send scale factor and receive scale factor
    • rto:<icsk_rto> โ€” tcp re-transmission timeout value. the unit is millisecond โฑ๏ธ
    • backoff:<icsk_backoff> โ€” used for exponential backoff re-transmission. the actual re-transmission timeout value is icsk_rto << icsk_backoff
    • rtt:<rtt>/<rttvar> โ€” rtt is the average round trip time, rttvar is the mean deviation of rtt. their units are millisecond
    • ato:<ato> โ€” ack timeout. unit is millisecond, used for delay ack mode
    • mss:<mss> โ€” max segment size
    • cwnd:<cwnd> โ€” congestion window size
    • pmtu:<pmtu> โ€” path MTU value
    • ssthresh:<ssthresh> โ€” tcp congestion window slow start threshold
    • bytes_acked:<bytes_acked> โ€” bytes acked โœ…
    • bytes_received:<bytes_received> โ€” bytes received
    • segs_out:<segs_out> โ€” segments sent out
    • segs_in:<segs_in> โ€” segments received
    • send <send_bps>bps โ€” egress bps
    • lastsnd:<lastsnd> โ€” how long it has been since the last packet sent. the unit is millisecond
    • lastrcv:<lastrcv> โ€” how long it has been since the last packet received. the unit is millisecond
    • lastack:<lastack> โ€” how long it has been since the last ack received. the unit is millisecond
    • pacing_rate <pacing_rate>bps/<max_pacing_rate>bps โ€” the pacing rate and max pacing rate
    • rcv_space:<rcv_space> โ€” a helper variable for TCP internal auto tuning socket receive buffer
    • MPTCP subflow information:
tcp-ulp-mptcp flags:[MmBbJjecv]
token:<rem_token(rem_id)/loc_token(loc_id)> seq:<sn> sfseq:<ssn>
ssnoff:<off> maplen:<maplen>
  • --tos โ€” show ToS and priority information. the below fields may appear:
    • tos โ€” IPv4 Type-of-Service byte
    • tclass โ€” IPv6 Traffic Class byte
    • class_id โ€” Class id set by net_cls cgroup. if class is zero, this shows priority set by SO_PRIORITY.
  • --cgroup โ€” show cgroup information. the below fields may appear:
    • cgroup โ€” Cgroup v2 pathname. this pathname is relative to the mount point of the hierarchy ๐Ÿ—‚๏ธ
  • --tipcinfo โ€” show internal tipc socket information.
  • -K, --kill โ€” attempts to forcibly close sockets. this option displays sockets that are successfully closed, and silently skips sockets that the kernel does not support closing. she supports IPv4 and IPv6 sockets only.
โš ๏ธ hello bestie, this one closes sockets. forcibly. like, that's the whole point. read the room before you type it ๐Ÿ’€
  • -s, --summary โ€” print summary statistics. this option does not parse socket lists โ€” it obtains the summary from various sources instead. it's useful when the amount of sockets is so huge that parsing /proc/net/tcp is painful ๐Ÿ˜ญ (and honestly, at that scale? it is painful.)
  • -E, --events โ€” continually display sockets as they are destroyed ๐Ÿ’€โœจ
  • -Z, --context โ€” as the -p option, but also shows process security context. if the -T option is used, it also shows thread security context. for netlink(7) sockets, the initiating process context is displayed as follows:
    1. If valid pid, show the process context.
    2. If destination is kernel (pid = 0), show kernel initial context.
    3. If a unique identifier has been allocated by the kernel or netlink user, show context as "unavailable". this will generally indicate that a process has more than one netlink socket active.
  • -z, --contexts โ€” as the -Z option, but also shows the socket context. the socket context is taken from the associated inode and is not the actual socket context held by the kernel. sockets are typically labeled with the context of the creating process, however the context shown will reflect any policy role, type and/or range transition rules applied, and is therefore a useful reference. ๐Ÿท๏ธ
  • -N NSNAME, --net=NSNAME โ€” switch to the specified network namespace name. hopping dimensions ๐ŸŒ€
  • -b, --bpf โ€” show socket classic BPF filters. (only administrators are allowed to get this information, so don't get mad at her if she won't tell you ๐Ÿ”)
  • -4, --ipv4 โ€” display only IP version 4 sockets (alias for -f inet).
  • -6, --ipv6 โ€” display only IP version 6 sockets (alias for -f inet6).
  • -0, --packet โ€” display PACKET sockets (alias for -f link).
  • -t, --tcp โ€” display TCP sockets.
  • -u, --udp โ€” display UDP sockets.
  • -w, --raw โ€” display RAW sockets.
  • -x, --unix โ€” display Unix domain sockets (alias for -f unix).
  • -S, --sctp โ€” display SCTP sockets.
  • --tipc โ€” display tipc sockets (alias for -f tipc).
  • --vsock โ€” display vsock sockets (alias for -f vsock).
  • --xdp โ€” display XDP sockets (alias for -f xdp).
  • -M, --mptcp โ€” display MPTCP sockets.
  • --inet-sockopt โ€” display inet socket options.
  • -f FAMILY, --family=FAMILY โ€” display sockets of type FAMILY. currently the following families are supported: unix, inet, inet6, link, netlink, vsock, tipc, xdp. ๐Ÿฆ‹
  • -A QUERY, --query=QUERY, --socket=QUERY โ€” bestie, this is your socket-table menu ๐Ÿ’… Give it a comma-separated list of socket tables to dump. The identifiers that hit: all, inet, tcp, udp, raw, unix, packet, netlink, unix_dgram, unix_stream, unix_seqpacket, packet_raw, packet_dgram, sctp, tipc, vsock_stream, vsock_dgram, xdp, mptcp. And plot twist: you can slap a ! in front of any item to exclude that socket table from the dump. So 'all,!tcp' vibes are fully valid. ๐Ÿ™ˆ
  • -D FILE, --diag=FILE โ€” shows you nothing on screen, iconic behavior honestly โ€” it just dumps raw info about TCP sockets into FILE after applying your filters. And if FILE is -, stdout gets it instead. โœจ
  • -F FILE, --filter=FILE โ€” read your filter info from FILE. Every single line of FILE gets interpreted like one command line option. If FILE is -, it reads from stdin. ๐ŸŽ€
  • --bpf-maps โ€” pretty-prints all the BPF socket-local data entries for each socket. So pretty. So much data. ๐Ÿฆ‹
  • --bpf-map-id=MAP_ID โ€” pretty-prints the BPF socket-local data entries for the map ID you asked for. And yes, you can use it more than once, stack 'em up. ๐ŸŒธ
  • FILTER := [ state STATE-FILTER ] [ EXPRESSION ] โ€” this is the shape of a filter. For the full deets on filters, go look at the official documentation, bestie, I'm just the messenger. ๐Ÿ’œ
FILTER := [ state STATE-FILTER ] [ EXPRESSION ]

๐Ÿซถ STATE-FILTER ๐Ÿซถ

STATE-FILTER lets you build an arbitrary lil' set of states to match against. Its syntax is a sequence of the keywords state and exclude, each followed by an identifier of a state. Mix and match, make it yours. ๐Ÿ’–

The available identifiers are:

  • All standard TCP states: established, syn-sent, syn-recv, fin-wait-1, fin-wait-2, time-wait, closed, close-wait, last-ack, listening and closing.
  • all โ€” for all the states. yes, every single one. ๐Ÿ‘‘
  • connected โ€” all the states except for listening and closed
  • synchronized โ€” all the connected states except for syn-sent
  • bucket โ€” states which are maintained as minisockets, i.e. time-wait and syn-recv
  • big โ€” the opposite of bucket
  • bound-inactive โ€” bound but otherwise inactive sockets (not listening, not connecting, etc.)

๐Ÿ”ฅ EXPRESSION ๐Ÿ”ฅ

EXPRESSION lets you filter based on specific criteria โ€” like a vibe check but for sockets. โœจ An EXPRESSION is a series of predicates combined by boolean operators. The possible operators, in increasing order of precedence, are or (or | or ||), and (or & or &&), and not (or !). If there's no operator between two consecutive predicates, an implicit and is assumed โ€” sneaky but true. And you can group subexpressions with "(" and ")". ๐ŸŽ€

The following predicates are supported:

  • {dst|src} [=] HOST โ€” tests if the destination or source matches HOST. See HOST SYNTAX for details, bestie, it's right below. ๐Ÿ‘‡
  • {dport|sport} [OP] [FAMILY:]:PORT โ€” compares the destination or source port to PORT. OP can be any of "<", "<=", "=", "!=", ">=" and ">", following normal arithmetic rules. FAMILY and PORT are as described in HOST SYNTAX below.
  • dev [=|!=] DEVICE โ€” matches based on the device the connection uses. DEVICE can either be a device name or the index of the interface. ๐Ÿฆ‹
  • fwmark [=|!=] MASK โ€” matches based on the fwmark value for the connection. This can either be a specific mark value, or a mark value followed by a "/" and a bitmask of which bits to use in the comparison. For example, "fwmark = 0x01/0x03" would match if the two least significant bits of the fwmark were 0x01. Math ate, honestly. ๐Ÿ’…
  • cgroup [=|!=] PATH โ€” matches if the connection is part of a cgroup at the given path.
  • autobound โ€” matches if the port or path of the source address was automatically allocated (rather than explicitly specified). no thoughts, just vibes. ๐ŸŒธ

Most operators have aliases ๐Ÿ‘ฏ and if you don't supply an operator, "=" is assumed. Each of the following groups of operators are all equivalent:

  • =, ==, eq
  • !=, ne, neq
  • >, gt
  • <, lt
  • >=, ge, geq
  • <=, le, leq
  • !, not
  • |, ||, or
  • &, &&, and

๐ŸŒˆ HOST SYNTAX ๐ŸŒˆ

The general host syntax is [FAMILY:]ADDRESS[:PORT]. Periodt.

FAMILY must be one of the families supported by the -f option. If you don't give it, it defaults to the family given with the -f option โ€” and if that's also missing, it'll assume either inet or inet6. Heads up though: all host conditions in the expression should either all be the same family, or be only inet and inet6. If there's some other mixture of families, the results will probably be unexpected. ๐Ÿ˜ญ Consider yourself warned, bestie.

The form of ADDRESS and PORT depends on the family used. "*" can be used as a wildcard for either the address or the port. Here's the tea for each family:

  • unix โ€” ADDRESS is a glob pattern (see fnmatch(3)) that will be matched case-insensitively against the unix socket's address. Both path and abstract names are supported. Unix addresses do not support a port, and "*" cannot be used as a wildcard. ๐Ÿ’€
  • link โ€” ADDRESS is the case-insensitive name of an Ethernet protocol to match. PORT is either a device name or a device index for the desired link device, as seen in the output of ip link.
  • netlink โ€” ADDRESS is a descriptor of the netlink family. Possible values come from /etc/iproute2/nl_protos. PORT is the port id of the socket, which is usually the same as the owning process id. The value "kernel" can be used to represent the kernel (port id of 0). ๐Ÿงš
  • vsock โ€” ADDRESS is an integer representing the CID address, and PORT is the port.
  • inet and inet6 โ€” ADDRESS is an ip address (either v4 or v6 depending on the family) or a DNS hostname that resolves to an ip address of the required version. An ipv6 address must be enclosed in "[" and "]" to disambiguate the port separator. The address may additionally have a prefix length given in CIDR notation (a slash followed by the prefix length in bits). PORT is either the numerical socket port, or the service name for the port to match.

๐Ÿ‘‘ USAGE EXAMPLES ๐Ÿ‘‘

ss -t -a

Display all TCP sockets.

ss -t -a -Z

Display all TCP sockets with process SELinux security contexts.

ss -u -a

Display all UDP sockets.

ss -o state established '( dport = :ssh or sport = :ssh )'

Display all established ssh connections.

ss -x src /tmp/.X11-unix/*

Find all local processes connected to X server.

ss -o state fin-wait-1 '( sport = :http or sport = :https )' dst 193.233.7/24

List all the tcp sockets in state FIN-WAIT-1 for our apache to network 193.233.7/24 and look at their timers. โฑ๏ธ

ss -a -A 'all,!tcp'

List sockets in all states from all socket tables but TCP.


๐Ÿ’œ SEE ALSO ๐Ÿ’œ


๐Ÿ’– AUTHOR ๐Ÿ’–

ss was written by Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>.

This manual page was written by Michael Prokop <mika@grml.org> for the Debian project (but may be used by others). absolute icons, the both of them. ๐Ÿ™Œ


And that's the whole SS(8) page, bestie โ€” SS(8), the one and only, straight from the iproute2 fam, dated like a lil' time capsule at the bottom. Go forth and inspect those sockets, you gorgeous main character. โœจ๐Ÿซถ๐ŸŒธ

๐Ÿ“ฆ where this page comes from