ss / netstat commands

Options, state filters, filter expressions and examples of ss, the socket statistics tool of iproute2, taken from the ss(8) manual page of iproute2 7.2.0 and grouped by task. Most rows are bare options to combine after ss; rows that begin with ss are whole commands the manual prints. With no option ss lists connected sockets only, so add -l or -a to see listeners. The last group holds netstat commands from the net-tools netstat(8) page, with the replacements it names.

100 commands in 10 sections. Checked row by row against ss(8) manual page, iproute2 7.2.0 (iproute2 upstream Git, rendered by man7.org) on . Edited by Jay.

Choosing socket types 15

CommandWhat it does
-tShow TCP socketsLong form --tcp; the manual's examples pair it with -a so that listening sockets appear as well.
-uShow UDP socketsLong form --udp; add -a, as the manual's example does, or only connected UDP sockets are listed.
-wShow raw socketsLong form --raw; the same table can be requested by name with -A raw.
-xShow Unix domain socketsLong form --unix, an alias for -f unix; a src or dst filter then takes a path pattern.
-SShow SCTP socketsLong form --sctp; sctp is also one of the identifiers -A understands.
-dShow DCCP socketsLong form --dccp; documented for 7.2.0, though the development manual has since dropped the option.
-MShow MPTCP socketsLong form --mptcp; an -A query names the same table mptcp.
-0Show packet socketsLong form --packet, an alias for -f link; host filters then name an Ethernet protocol and a device.
-4Show IPv4 sockets onlyLong form --ipv4, an alias for -f inet.
-6Show IPv6 sockets onlyLong form --ipv6, an alias for -f inet6.
--tipcShow TIPC socketsAn alias for -f tipc; --tipcinfo adds the internal details of each one.
--vsockShow vsock socketsAn alias for -f vsock; in host filters the address is the integer CID.
--xdpShow XDP socketsAn alias for -f xdp, with no single-letter form.
-f FAMILYSelect an address familyLong form --family=FAMILY; accepts unix, inet, inet6, link, netlink, vsock, tipc or xdp.
-A QUERYChoose socket tables to dumpLong form --query=QUERY or --socket=QUERY; a comma-separated list such as tcp,udp,unix, where a leading ! excludes a table.

Listening and connected sockets 6

CommandWhat it does
ssList connected socketsWith no option only open non-listening sockets that have an established connection are printed.
-lShow listening sockets onlyLong form --listening; without it or -a the listeners are left out of the output.
-aShow listening and connected socketsLong form --all; for TCP the non-listening part means established connections.
-BShow bound but inactive TCP socketsLong form --bound-inactive; these are bound sockets that are neither listening nor connecting, hidden unless requested.
-EWatch sockets being destroyedLong form --events; keeps running and prints each socket as it is torn down.
-KForce sockets closedLong form --kill; lists the sockets it managed to close, skips unsupported ones silently, and handles IPv4 and IPv6 only.

Output detail 16

CommandWhat it does
-nShow numeric portsLong form --numeric; service names are not looked up, and bandwidth values are exact instead of human-readable.
-rResolve addresses and portsLong form --resolve; replaces numeric addresses and ports with names where a lookup succeeds.
-HHide the header lineLong form --no-header; the column titles are dropped and only socket lines remain.
-OPrint one line per socketLong form --oneline; everything known about a socket stays on that socket's own line.
-QHide the queue columnsLong form --no-queues; drops the send and receive queue columns from the table.
-oShow timer informationLong form --options; TCP prints timer:(NAME,EXPIRE,RETRANS), the name being on, keepalive, timewait, persist or unknown.
-eShow extended socket detailsLong form --extended; appends the owning uid, the socket's inode number and its cookie.
-mShow socket memory usageLong form --memory; adds an skmem:(...) group with receive and send buffer allocations, backlog and drop counts.
-iShow internal TCP informationLong form --info; fields include the congestion algorithm, rto, rtt, mss, cwnd, ssthresh, pacing rate and byte and segment counters.
-sPrint summary statisticsLong form --summary; totals come from other sources without parsing the socket lists, which helps when sockets are very numerous.
--tosShow ToS and priorityAdds tos for IPv4, tclass for IPv6 and a class_id that falls back to the SO_PRIORITY value.
--tipcinfoShow internal TIPC detailsApplies to TIPC sockets, which --tipc or -f tipc selects.
--inet-sockoptShow inet socket options
-bShow classic BPF filtersLong form --bpf; the filters attached to a socket are readable by administrators only.
--bpf-mapsPrint BPF socket-local storagePretty-prints every socket-local data entry held in BPF maps, socket by socket.
--bpf-map-id=MAP_IDPrint one BPF map's entriesLimits the BPF socket-local output to the given map ID; repeat the option for several maps.

Process and security context 5

CommandWhat it does
-pShow owning processesLong form --processes; names the processes that are using each socket.
-TShow owning threadsLong form --threads; turns on -p as well, so thread and process appear together.
-ZShow process security contextLong form --context; works like -p plus the SELinux context, and covers threads too when -T is given.
-zShow socket security contextLong form --contexts; adds to -Z a socket context read from the inode, not the one the kernel itself holds.
--cgroupShow cgroup of each socketPrints the Cgroup v2 path as seen from where that hierarchy is mounted.

State filters 18

A state filter is written before the expression, and both parts are optional: the manual gives the filter as [ state STATE-FILTER ] [ EXPRESSION ].

CommandWhat it does
state establishedMatch established connectionsThe manual's ssh example uses it with -o to list live sessions and their timers.
state syn-sentMatch sockets in SYN-SENTThe one connected state that the synchronized set leaves out.
state syn-recvMatch sockets in SYN-RECVKept as a minisocket, so it also falls under the bucket set.
state fin-wait-1Match sockets in FIN-WAIT-1Used in the manual's Apache example together with a source-port test and a destination network.
state fin-wait-2Match sockets in FIN-WAIT-2
state time-waitMatch sockets in TIME-WAITLike syn-recv it is a minisocket state and belongs to the bucket set.
state closedMatch closed socketsTogether with listening, one of the two states the connected set omits.
state close-waitMatch sockets in CLOSE-WAIT
state last-ackMatch sockets in LAST-ACK
state listeningMatch listening socketsNot part of the connected set, which drops listening and closed sockets.
state closingMatch sockets in CLOSING
state allMatch every state
state connectedMatch all connected statesEvery state apart from listening and closed.
state synchronizedMatch synchronized statesThe connected set with syn-sent taken out.
state bucketMatch minisocket statesCovers time-wait and syn-recv, the two states kept as minisockets.
state bigMatch full-socket statesThe opposite of bucket: everything except time-wait and syn-recv.
state bound-inactiveMatch bound but inactive socketsBound sockets that are neither listening nor connecting, the kind the -B option displays for TCP.
exclude listeningRemove a state from the setThe exclude keyword takes any state identifier and subtracts it from the states being matched.

Address and port filters 11

An IPv6 address in a host filter goes inside [ ] so that its colons are not read as the port separator.

CommandWhat it does
dst HOSTMatch the destination addressAn optional = may follow dst; HOST is written as [FAMILY:]ADDRESS[:PORT].
src HOSTMatch the source addressFor Unix sockets HOST is a glob pattern, as in the manual's /tmp/.X11-unix/* example.
dport = :PORTMatch the destination portPORT is a number or service name; = may be replaced by any comparison operator or left out.
sport = :PORTMatch the source portThe port follows a colon, and an address family with its own colon may come first.
dev = DEVICEMatch the network deviceDEVICE is an interface name or index; write != to exclude that device.
fwmark = MASKMatch the firewall markMASK is a mark value, optionally followed by / and a bitmask of the bits to compare.
fwmark = 0x01/0x03Match masked fwmark bitsThe manual's example: true when the two lowest bits of the mark equal 0x01.
cgroup = PATHMatch sockets in a cgroupTrue for connections that belong to the cgroup at PATH; != reverses the test.
autoboundMatch automatically assigned portsTrue when the source port or path was allocated automatically, not set explicitly by the program.
[FAMILY:]ADDRESS[:PORT]General host syntaxFAMILY defaults to the one given with -f, else inet or inet6; * is a wildcard for address or port.
dst 193.233.7/24Match a destination networkAn inet address may carry a CIDR prefix length, here a /24 taken from the manual's Apache example.

Comparison and boolean operators 10

CommandWhat it does
= == eqEqual toThe three spellings are interchangeable, and = is assumed when no operator is written.
!= ne neqNot equal toAlso the form the dev, fwmark and cgroup tests accept for a negative match.
> gtGreater than
< ltLess than
>= ge geqGreater than or equal to
<= le leqLess than or equal to
! notNegate a conditionBinds tighter than the other two boolean operators, the highest of the three precedence levels.
& && andRequire both conditionsAssumed automatically between two tests written side by side with no operator.
| || orMatch either conditionLowest precedence of the three, so group it with parentheses when mixing it with and.
( EXPRESSION )Group conditionsThe manual's examples wrap the whole parenthesised group in single quotes.

Namespaces, files and help 5

CommandWhat it does
-N NSNAMESwitch network namespaceLong form --net=NSNAME; ss reports the sockets of that named namespace instead of the current one.
-D FILEDump raw TCP socket dataLong form --diag=FILE; nothing is displayed, filters still apply, and - sends the dump to stdout.
-F FILERead filters from a fileLong form --filter=FILE; each line counts as one command-line option, and - reads standard input.
-hShow option summaryLong form --help; prints a short summary of the available options.
-VShow versionLong form --version; prints the version information of the installed ss.

Examples from the manual 7

CommandWhat it does
ss -t -aList all TCP socketsCombines the TCP table with -a so listening sockets are included.
ss -t -a -ZList TCP sockets with SELinux contextsEach socket line also carries the owning process and its security context.
ss -u -aList all UDP socketsSame pattern as the TCP example, with -u selecting the UDP table.
ss -o state established '( dport = :ssh or sport = :ssh )'List established SSH connectionsMatches the ssh service port on either end and adds timer information through -o.
ss -x src /tmp/.X11-unix/*Find X server clientsSelects Unix sockets whose source address matches the X11 socket path pattern.
ss -o state fin-wait-1 '( sport = :http or sport = :https )' dst 193.233.7/24List FIN-WAIT-1 web socketsWeb-server sockets in FIN-WAIT-1 whose peer lies in 193.233.7/24, shown with their timers.
ss -a -A 'all,!tcp'List every table except TCPEvery state and every socket table is dumped, apart from TCP, which the !tcp item removes.

Netstat commands and replacements 7

netstat(8) describes netstat as mostly obsolete and names ss as its replacement, with ip route, ip -s link and ip maddr for the -r, -i and -g modes.

CommandWhat it does
netstatList open sockets with net-toolsPrints the active sockets of every configured address family unless one is named.
netstat -tulpnList listening TCP and UDP portsThe manual's example for finding which process listens on a port; showing PIDs requires root.
netstat -rnShow the route table numericallyPassing -n prints IP addresses in place of hostnames.
netstat -rShow kernel routing tablesMarked obsolete: the manual names ip route as the command to use now.
netstat -iShow interface statisticsTabulates interfaces with their receive and transmit error counters; the manual points to ip -s link.
netstat -gShow multicast group membershipsCovers IPv4 and IPv6 groups; the manual points to ip maddr as the current command.
netstat -sShow per-protocol statisticsPrints SNMP summary counters per protocol; the synopsis allows -t, -u, -U, -S and -w with it.

Notes

The combinations people actually type

Most invocations combine a socket-type letter with a state option: -l shows only listening sockets and -a shows listening and connected ones, while ss -t -a and ss -u -a restrict the list to TCP and UDP. Add -n to keep ports as numbers instead of service names and -p to show the processes using each socket. Written together the letters give ss -tulpn, the same letters as the netstat -tulpn example in netstat(8): every listening TCP and UDP port with the program behind it. -s prints summary statistics without parsing the socket lists, which is a quick check on a busy server.

Filtering

Rather than piping to grep, ss accepts a filter after the options: an optional state filter, then an expression. dst HOST and src HOST match by address — ss -t dst 10.0.0.5 — and dport = :PORT and sport = :PORT match by port, with the other comparison operators available as well: ss -t sport = :22. State filters such as state established or state time-wait answer "how many connections are stuck", and exclude listening takes a state out of the set. -4 and -6 restrict to one IP family, and -x with a path pattern finds Unix-socket clients, as in ss -x src /tmp/.X11-unix/*.

Diagnostics

-i prints internal TCP information per connection — congestion window, round-trip time, retransmission timeout — which helps tell a network problem from an application one. -o shows timers such as keepalive and retransmission countdowns, -m socket memory, and -e extended details including the socket's inode. -E watches sockets as they are destroyed, and -K attempts to forcibly close sockets: it handles IPv4 and IPv6 only, prints the ones it closed and silently skips those the kernel does not support closing.

Questions

What is the ss equivalent of netstat -tulpn?

ss -tulpn. The letters mean the same in both manuals: -t TCP, -u UDP, -l listening sockets, -p processes and -n numeric output. netstat(8) itself calls netstat mostly obsolete and names ss as the replacement.

How do I see connections to a specific port?

ss -t state established '( dport = :443 or sport = :443 )', the pattern of the manual's ssh example, or simply ss -t sport = :443 for the local side.

Why does ss not show process names?

Process details appear only with -p. ss(8) does not mention privileges, but netstat(8) documents the limit for its own -p: a hyphen is shown when the user has no permission to inspect the other process, and its example notes that listing PIDs requires root. Run ss with sudo when sockets of other users come back without a process.

How do I count connections by state?

-s prints summary statistics for the whole host. For one state, count the lines a state filter returns, with -H so the header line is not counted: ss -H -t state time-wait | wc -l.

Sources and checks

Every row on this page was matched to a line in the documentation above on . A binding that could not be found there is not listed.

Found a wrong or missing key? Tell us and it gets checked against the source. How we verify describes the process and its limits.