ss
(8)another utility to investigate sockets
Options
46-h--helpShow summary of options.
-V--versionOutput version information.
-H--no-headerSuppress header line.
-Q--no-queuesSuppress sending and receiving queue columns.
-O--onelinePrint each socket's data on a single line.
-n--numericDo not try to resolve service names. Show exact bandwidth values, instead of human-readable.
-r--resolveTry to resolve numeric address/ports.
-a--allDisplay both listening and non-listening (for TCP this means established connections) sockets.
-l--listeningDisplay only listening sockets (these are omitted by default).
-B--bound-inactiveDisplay only TCP bound but inactive (not listening, connecting, etc.) sockets (these are omitted by default).
-o--optionsShow timer information. For TCP protocol, the output format is:
-e--extendedShow detailed socket information. The output format is:
-m--memoryShow socket memory usage. The output format is:
-p--processesShow process using socket.
-T--threadsShow thread using socket. Implies -p.
-i--infoShow internal TCP information. Below fields may appear:
--tosShow ToS and priority information. Below fields may appear:
--cgroupShow cgroup information. Below fields may appear:
--tipcinfoShow internal tipc socket information.
-K--killAttempts to forcibly close sockets. This option displays sockets that are successfully closed and silently skips sockets that the kernel does not support closing. It supports IPv4 and IPv6 sockets only.
-s--summaryPrint summary statistics. This option does not parse socket lists obtaining summary from various sources. It is useful when amount of sockets is so huge that parsing /proc/net/tcp is painful.
-E--eventsContinually display sockets as they are destroyed
-Z--contextAs the -p option but also shows process security context. If the -T option is used, also shows thread security context. For netlink(7) sockets the initiating process context is displayed as follows:
-z--contextsAs 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--netSwitch to the specified network namespace name.
-b--bpfShow socket classic BPF filters (only administrators are allowed to get these information).
-4--ipv4Display only IP version 4 sockets (alias for -f inet).
-6--ipv6Display only IP version 6 sockets (alias for -f inet6).
-0--packetDisplay PACKET sockets (alias for -f link).
-t--tcpDisplay TCP sockets.
-u--udpDisplay UDP sockets.
-d--dccpDisplay DCCP sockets.
-w--rawDisplay RAW sockets.
-x--unixDisplay Unix domain sockets (alias for -f unix).
-S--sctpDisplay SCTP sockets.
--tipcDisplay tipc sockets (alias for -f tipc).
--vsockDisplay vsock sockets (alias for -f vsock).
--xdpDisplay XDP sockets (alias for -f xdp).
-M--mptcpDisplay MPTCP sockets.
--inet-sockoptDisplay inet socket options.
-f--familyDisplay sockets of type FAMILY. Currently the following families are supported: unix, inet, inet6, link, netlink, vsock, tipc, xdp.
-A--query--socketList of socket tables to dump, separated by commas. The following identifiers are understood: all, inet, tcp, udp, raw, unix, packet, netlink, unix_dgram, unix_stream, unix_seqpacket, packet_raw, packet_dgram, dccp, sctp, tipc, vsock_stream, vsock_dgram, xdp, mptcp. Any item in the list may optionally be prefixed by an exclamation mark (!) to exclude that socket table from being dumped.
-D--diagDo not display anything, just dump raw information about TCP sockets to FILE after applying filters. If FILE is - stdout is used.
-F--filterRead filter information from FILE. Each line of FILE is interpreted like single command line option. If FILE is - stdin is used.
--bpf-mapsPretty-print all the BPF socket-local data entries for each socket.
--bpf-map-idPretty-print the BPF socket-local data entries for the requested map ID. Can be used more than once.
DESCRIPTION
STATE-FILTER
STATE-FILTER allows one to construct arbitrary set of states to match. Its syntax is sequence of keywords state and exclude followed by identifier of state.
- 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
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 - opposite to bucket
bound-inactive - bound but otherwise inactive sockets (not listening, connecting, etc.)
EXPRESSION
EXPRESSION allows filtering based on specific criteria. EXPRESSION consists of 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 no operator is between consecutive predicates, an implicit and operator is assumed. Subexpressions can be grouped with "(" and ")".
The following predicates are supported:
- {dst|src} [=] HOST
- Test if the destination or source matches HOST. See HOST SYNTAX for details.
- {dport|sport} [OP] [FAMILY:]:PORT
- Compare 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
- Match 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.
- cgroup [=|!=] PATH
- Match if the connection is part of a cgroup at the given path.
- autobound
- Match if the port or path of the source address was automatically allocated (rather than explicitly specified).
Most operators have aliases. If no operator is supplied "=" 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].
FAMILY must be one of the families supported by the -f option. If not given it defaults to the family given with the -f option, and if that is also missing, will assume either inet or inet6. Note that all host conditions in the expression should either all be the same family or be only inet and inet6. If there is some other mixture of families, the results will probably be unexpected.
The form of ADDRESS and PORT depends on the family used. "*" can be used as a wildcard for either the address or port. The details for each family are as follows:
- 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.
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).