LinuxCommandLibrary

systemctl-list-sockets

List systemd listening sockets

TLDR

List active socket units currently in memory

$ systemctl list-sockets
copy

List active socket units with their socket types
$ systemctl list-sockets --show-types
copy

List all socket units, including inactive and failed ones
$ systemctl list-sockets [[-a|--all]]
copy

List socket units filtered by state
$ systemctl list-sockets --state [active|inactive|failed|...]
copy

List socket units matching a name pattern
$ systemctl list-sockets [pattern1 pattern2 ...]
copy

SYNOPSIS

systemctl list-sockets [OPTIONS...] [PATTERN...]

PARAMETERS

-a, --all
    Show all loaded socket units, including those that are inactive or have failed. By default, only active and listening sockets are shown.

--full
    Do not abbreviate unit names or truncate output fields. Useful for seeing complete unit names.

--no-legend
    Do not print the header line that describes the columns. Useful for scripting or machine-readable output.

--no-pager
    Do not pipe output into a pager. Output is printed directly to standard output.

--output=FORMAT
    Control the output format. Common formats include short (default), plain (equivalent to --no-pager --no-legend), json, json-pretty, etc.

--plain
    Equivalent to --output=plain --no-legend. Displays output without a pager or header.

--user
    Operate on the user systemd instance. By default, systemctl operates on the system-wide systemd instance.

--system
    Explicitly operate on the system systemd instance (this is the default behavior).

[PATTERN...]
    One or more glob patterns to filter the list of socket units by their name. Only units matching any of the patterns will be displayed.

DESCRIPTION

systemctl list-sockets is a subcommand of the systemctl utility, part of the systemd init system. It provides a comprehensive overview of all loaded and listening socket units managed by systemd. Unlike generic network utilities like ss or netstat, this command focuses specifically on sockets configured and activated via systemd's socket activation mechanism. It displays crucial information such as the socket's listening address or path, its type (e.g., stream, datagram, fifo), the systemd unit it activates upon connection (typically a service unit), and its current state.

This command is invaluable for administrators and developers to verify that services configured for socket activation are correctly listening, debug connectivity issues, and understand dependencies between socket units and their corresponding service units. It helps in quickly identifying which network or IPC endpoints are being managed by systemd and are ready to trigger service startups on demand, thereby optimizing resource usage and improving system startup times.

CAVEATS

systemctl list-sockets only displays sockets explicitly managed by systemd through socket units (.socket files). It will not show all listening sockets on your system; for a comprehensive list of all open network sockets, use utilities like ss -lntu or netstat -lntu. Output can be extensive on systems with many services; using filtering patterns or piping to a pager (or disabling it with --no-pager) might be necessary. To list system-wide sockets, root privileges are generally required.

OUTPUT COLUMNS EXPLAINED

The default output of systemctl list-sockets includes several columns:

  • LISTEN: The socket address or path being listened on (e.g., [::]:22 for SSH, or a file path for a Unix domain socket).
  • UNIT: The name of the socket unit (e.g., ssh.socket).
  • ACTIVATES: The service or other unit that will be activated when a connection is received on this socket (e.g., ssh.service).
  • STATE: The current state of the socket unit (e.g., listening, inactive, failed).

UNDERSTANDING SOCKET ACTIVATION

Socket activation is a key feature of systemd that allows services to be started on demand rather than at boot time. When a service is configured for socket activation, systemd listens on the service's port (or Unix domain socket path). The actual service process is only started when an incoming connection arrives on that socket. This approach provides several benefits: faster boot times, reduced resource consumption for infrequently used services, and improved robustness by allowing services to restart without dropping existing connections if the socket remains open.

HISTORY

The systemctl list-sockets command is an integral part of systemd, which was first introduced in 2010 and rapidly adopted as the default init system across many Linux distributions, replacing the traditional SysVinit. Its development focused on improving boot times, providing parallel service startup, and offering advanced features like socket activation. The ability to list these socket units directly via systemctl emerged as a natural requirement for administering a systemd-centric system, allowing administrators to inspect the state of socket-activated services without delving into configuration files or generalized network tools. It underscores systemd's design philosophy of making system state transparent and manageable through a unified command-line interface.

SEE ALSO

systemctl(1), systemd.socket(5), systemd(1), ss(8), netstat(8), journalctl(1)

Copied to clipboard