2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="systemd.socket" xmlns:xi="http://www.w3.org/2001/XInclude">
8 <title>systemd.socket</title>
9 <productname>systemd</productname>
13 <refentrytitle>systemd.socket</refentrytitle>
14 <manvolnum>5</manvolnum>
18 <refname>systemd.socket</refname>
19 <refpurpose>Socket unit configuration</refpurpose>
23 <para><filename><replaceable>socket</replaceable>.socket</filename></para>
27 <title>Description</title>
29 <para>A unit configuration file whose name ends in
30 <literal>.socket</literal> encodes information about an IPC or
31 network socket or a file system FIFO controlled and supervised by
32 systemd, for socket-based activation.</para>
34 <para>This man page lists the configuration options specific to
36 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
37 for the common options of all unit configuration files. The common
38 configuration items are configured in the generic [Unit] and
39 [Install] sections. The socket specific configuration options are
40 configured in the [Socket] section.</para>
42 <para>Additional options are listed in
43 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
44 which define the execution environment the
45 <option>ExecStartPre=</option>, <option>ExecStartPost=</option>,
46 <option>ExecStopPre=</option> and <option>ExecStopPost=</option>
47 commands are executed in, and in
48 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
49 which define the way the processes are terminated, and in
50 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
51 which configure resource control settings for the processes of the
54 <para>For each socket unit, a matching service unit must exist,
55 describing the service to start on incoming traffic on the socket
57 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
58 for more information about .service units). The name of the
59 .service unit is by default the same as the name of the .socket
60 unit, but can be altered with the <option>Service=</option> option
61 described below. Depending on the setting of the
62 <option>Accept=</option> option described below, this .service
63 unit must either be named like the .socket unit, but with the
64 suffix replaced, unless overridden with <option>Service=</option>;
65 or it must be a template unit named the same way. Example: a
66 socket file <filename>foo.socket</filename> needs a matching
67 service <filename>foo.service</filename> if
68 <option>Accept=no</option> is set. If
69 <option>Accept=yes</option> is set, a service template
70 <filename>foo@.service</filename> must exist from which services
71 are instantiated for each incoming connection.</para>
73 <para>No implicit <varname>WantedBy=</varname> or
74 <varname>RequiredBy=</varname> dependency from the socket to the
75 service is added. This means that the service may be started
76 without the socket, in which case it must be able to open sockets
77 by itself. To prevent this, an explicit
78 <varname>Requires=</varname> dependency may be added.</para>
80 <para>Socket units may be used to implement on-demand starting of
81 services, as well as parallelized starting of services. See the
82 blog stories linked at the end for an introduction.</para>
84 <para>Note that the daemon software configured for socket activation with socket units needs to be able
85 to accept sockets from systemd, either via systemd's native socket passing interface (see
86 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
87 details about the precise protocol used and the order in which the file descriptors are passed) or via
88 traditional <citerefentry
89 project='freebsd'><refentrytitle>inetd</refentrytitle><manvolnum>8</manvolnum></citerefentry>-style
90 socket passing (i.e. sockets passed in via standard input and output, using
91 <varname>StandardInput=socket</varname> in the service file).</para>
93 <para>All network sockets allocated through <filename>.socket</filename> units are allocated in the host's network
94 namespace (see <citerefentry
95 project='man-pages'><refentrytitle>network_namespaces</refentrytitle><manvolnum>7</manvolnum></citerefentry>). This
96 does not mean however that the service activated by a configured socket unit has to be part of the host's network
97 namespace as well. It is supported and even good practice to run services in their own network namespace (for
98 example through <varname>PrivateNetwork=</varname>, see
99 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>), receiving only
100 the sockets configured through socket-activation from the host's namespace. In such a set-up communication within
101 the host's network namespace is only permitted through the activation sockets passed in while all sockets allocated
102 from the service code itself will be associated with the service's own namespace, and thus possibly subject to a
103 restrictive configuration.</para>
107 <title>Automatic Dependencies</title>
110 <title>Implicit Dependencies</title>
112 <para>The following dependencies are implicitly added:</para>
115 <listitem><para>Socket units automatically gain a <varname>Before=</varname>
116 dependency on the service units they activate.</para></listitem>
118 <listitem><para>Socket units referring to file system paths (such as <constant>AF_UNIX</constant>
119 sockets or FIFOs) implicitly gain <varname>Requires=</varname> and <varname>After=</varname>
120 dependencies on all mount units necessary to access those paths.</para></listitem>
122 <listitem><para>Socket units using the <varname>BindToDevice=</varname>
123 setting automatically gain a <varname>BindsTo=</varname> and
124 <varname>After=</varname> dependency on the device unit
125 encapsulating the specified network interface.</para></listitem>
128 <para>Additional implicit dependencies may be added as result of
129 execution and resource control parameters as documented in
130 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
132 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
136 <title>Default Dependencies</title>
138 <para>The following dependencies are added unless
139 <varname>DefaultDependencies=no</varname> is set:</para>
142 <listitem><para>Socket units automatically gain a
143 <varname>Before=</varname> dependency on
144 <filename>sockets.target</filename>.</para></listitem>
146 <listitem><para>Socket units automatically gain a pair of
147 <varname>After=</varname> and <varname>Requires=</varname>
148 dependency on <filename>sysinit.target</filename>, and a pair of
149 <varname>Before=</varname> and <varname>Conflicts=</varname>
150 dependencies on <filename>shutdown.target</filename>. These
151 dependencies ensure that the socket unit is started before normal
152 services at boot, and is stopped on shutdown. Only sockets
153 involved with early boot or late system shutdown should disable
154 <varname>DefaultDependencies=</varname> option.</para></listitem>
160 <title>Options</title>
162 <para>Socket unit files may include [Unit] and [Install] sections, which are described in
163 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
166 <para>Socket unit files must include a [Socket] section, which carries
167 information about the socket or FIFO it supervises. A number of
168 options that may be used in this section are shared with other
169 unit types. These options are documented in
170 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
171 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry> and
172 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
173 The options specific to the [Socket] section of socket units are
174 the following:</para>
176 <variablelist class='unit-directives'>
178 <term><varname>ListenStream=</varname></term>
179 <term><varname>ListenDatagram=</varname></term>
180 <term><varname>ListenSequentialPacket=</varname></term>
181 <listitem><para>Specifies an address to listen on for a stream
182 (<constant>SOCK_STREAM</constant>), datagram
183 (<constant>SOCK_DGRAM</constant>), or sequential packet
184 (<constant>SOCK_SEQPACKET</constant>) socket, respectively.
185 The address can be written in various formats:</para>
187 <para>If the address starts with a slash
188 (<literal>/</literal>), it is read as file system socket in
189 the <constant>AF_UNIX</constant> socket family.</para>
191 <para>If the address starts with an at symbol
192 (<literal>@</literal>), it is read as abstract namespace
193 socket in the <constant>AF_UNIX</constant> family. The
194 <literal>@</literal> is replaced with a
195 <constant>NUL</constant> character before binding. For
197 <citerefentry project='man-pages'><refentrytitle>unix</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
199 <para>If the address string is a single number, it is read as
200 port number to listen on via IPv6. Depending on the value of
201 <varname>BindIPv6Only=</varname> (see below) this might result
202 in the service being available via both IPv6 and IPv4
203 (default) or just via IPv6.
206 <para>If the address string is a string in the format
207 <literal><replaceable>v.w.x.y</replaceable>:<replaceable>z</replaceable></literal>, it is interpreted
208 as IPv4 address <replaceable>v.w.x.y</replaceable> and port <replaceable>z</replaceable>.</para>
210 <para>If the address string is a string in the format
211 <literal>[<replaceable>x</replaceable>]:<replaceable>y</replaceable></literal>, it is interpreted as
212 IPv6 address <replaceable>x</replaceable> and port <replaceable>y</replaceable>. An optional
213 interface scope (interface name or number) may be specified after a <literal>%</literal> symbol:
214 <literal>[<replaceable>x</replaceable>]:<replaceable>y</replaceable>%<replaceable>dev</replaceable></literal>.
215 Interface scopes are only useful with link-local addresses, because the kernel ignores them in other
216 cases. Note that if an address is specified as IPv6, it might still make the service available via
217 IPv4 too, depending on the <varname>BindIPv6Only=</varname> setting (see below).</para>
219 <para>If the address string is a string in the format
220 <literal>vsock:<replaceable>x</replaceable>:<replaceable>y</replaceable></literal>, it is read as CID
221 <replaceable>x</replaceable> on a port <replaceable>y</replaceable> address in the
222 <constant>AF_VSOCK</constant> family. The CID is a unique 32-bit integer identifier in
223 <constant>AF_VSOCK</constant> analogous to an IP address. Specifying the CID is optional, and may be
224 set to the empty string. <literal>vsock</literal> may be replaced with
225 <literal>vsock-stream</literal>, <literal>vsock-dgram</literal> or <literal>vsock-seqpacket</literal>
226 to force usage of the corresponding socket type.</para>
228 <para>Note that <constant>SOCK_SEQPACKET</constant> (i.e.
229 <varname>ListenSequentialPacket=</varname>) is only available
230 for <constant>AF_UNIX</constant> sockets.
231 <constant>SOCK_STREAM</constant> (i.e.
232 <varname>ListenStream=</varname>) when used for IP sockets
233 refers to TCP sockets, <constant>SOCK_DGRAM</constant> (i.e.
234 <varname>ListenDatagram=</varname>) to UDP.</para>
236 <para>These options may be specified more than once, in which
237 case incoming traffic on any of the sockets will trigger
238 service activation, and all listed sockets will be passed to
239 the service, regardless of whether there is incoming traffic
240 on them or not. If the empty string is assigned to any of
241 these options, the list of addresses to listen on is reset,
242 all prior uses of any of these options will have no
245 <para>It is also possible to have more than one socket unit
246 for the same service when using <varname>Service=</varname>,
247 and the service will receive all the sockets configured in all
248 the socket units. Sockets configured in one unit are passed in
249 the order of configuration, but no ordering between socket
250 units is specified.</para>
252 <para>If an IP address is used here, it is often desirable to
253 listen on it before the interface it is configured on is up
254 and running, and even regardless of whether it will be up and
255 running at any point. To deal with this, it is recommended to
256 set the <varname>FreeBind=</varname> option described
257 below.</para></listitem>
261 <term><varname>ListenFIFO=</varname></term>
262 <listitem><para>Specifies a file system FIFO (see <citerefentry
263 project='man-pages'><refentrytitle>fifo</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
264 details) to listen on. This expects an absolute file system path as argument. Behavior otherwise is
265 very similar to the <varname>ListenDatagram=</varname> directive above.</para></listitem>
269 <term><varname>ListenSpecial=</varname></term>
270 <listitem><para>Specifies a special file in the file system to
271 listen on. This expects an absolute file system path as
272 argument. Behavior otherwise is very similar to the
273 <varname>ListenFIFO=</varname> directive above. Use this to
274 open character device nodes as well as special files in
275 <filename>/proc/</filename> and
276 <filename>/sys/</filename>.</para></listitem>
280 <term><varname>ListenNetlink=</varname></term>
281 <listitem><para>Specifies a Netlink family to create a socket
282 for to listen on. This expects a short string referring to the
283 <constant>AF_NETLINK</constant> family name (such as
284 <varname>audit</varname> or <varname>kobject-uevent</varname>)
285 as argument, optionally suffixed by a whitespace followed by a
286 multicast group integer. Behavior otherwise is very similar to
287 the <varname>ListenDatagram=</varname> directive
288 above.</para></listitem>
292 <term><varname>ListenMessageQueue=</varname></term>
293 <listitem><para>Specifies a POSIX message queue name to listen on (see <citerefentry
294 project='man-pages'><refentrytitle>mq_overview</refentrytitle><manvolnum>7</manvolnum></citerefentry>
295 for details). This expects a valid message queue name (i.e. beginning with
296 <literal>/</literal>). Behavior otherwise is very similar to the <varname>ListenFIFO=</varname>
297 directive above. On Linux message queue descriptors are actually file descriptors and can be
298 inherited between processes.</para></listitem>
302 <term><varname>ListenUSBFunction=</varname></term>
303 <listitem><para>Specifies a <ulink
304 url="https://docs.kernel.org/usb/functionfs.html">USB
305 FunctionFS</ulink> endpoints location to listen on, for
306 implementation of USB gadget functions. This expects an
307 absolute file system path of a FunctionFS mount point as the argument.
308 Behavior otherwise is very similar to the <varname>ListenFIFO=</varname>
309 directive above. Use this to open the FunctionFS endpoint
310 <filename>ep0</filename>. When using this option, the
311 activated service has to have the
312 <varname>USBFunctionDescriptors=</varname> and
313 <varname>USBFunctionStrings=</varname> options set.
316 <xi:include href="version-info.xml" xpointer="v227"/></listitem>
320 <term><varname>SocketProtocol=</varname></term>
321 <listitem><para>Takes one of <option>udplite</option>,
322 <option>sctp</option> or <option>mptcp</option>. The socket will use
323 the UDP-Lite (<constant>IPPROTO_UDPLITE</constant>), SCTP
324 (<constant>IPPROTO_SCTP</constant>) or MPTCP
325 (<constant>IPPROTO_MPTCP</constant>) protocol, respectively.</para>
327 <xi:include href="version-info.xml" xpointer="v229"/>
332 <term><varname>BindIPv6Only=</varname></term>
333 <listitem><para>Takes one of <option>default</option>,
334 <option>both</option> or <option>ipv6-only</option>. Controls
335 the IPV6_V6ONLY socket option (see
336 <citerefentry project='die-net'><refentrytitle>ipv6</refentrytitle><manvolnum>7</manvolnum></citerefentry>
337 for details). If <option>both</option>, IPv6 sockets bound
338 will be accessible via both IPv4 and IPv6. If
339 <option>ipv6-only</option>, they will be accessible via IPv6
340 only. If <option>default</option> (which is the default,
341 surprise!), the system wide default setting is used, as
343 <filename>/proc/sys/net/ipv6/bindv6only</filename>, which in
344 turn defaults to the equivalent of
345 <option>both</option>.</para>
350 <term><varname>Backlog=</varname></term>
351 <listitem><para>Takes an unsigned 32-bit integer argument. Specifies the number of connections to
352 queue that have not been accepted yet. This setting matters only for stream and sequential packet
354 <citerefentry><refentrytitle>listen</refentrytitle><manvolnum>2</manvolnum></citerefentry> for
355 details. Defaults to 4294967295. Note that this value is silently capped by the
356 <literal>net.core.somaxconn</literal> sysctl, which typically defaults to 4096, so typically
357 the sysctl is the setting that actually matters.</para></listitem>
361 <term><varname>BindToDevice=</varname></term>
362 <listitem><para>Specifies a network interface name to bind this socket to. If set, traffic will only
363 be accepted from the specified network interfaces. This controls the
364 <constant>SO_BINDTODEVICE</constant> socket option (see <citerefentry
365 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
366 details). If this option is used, an implicit dependency from this socket unit on the network
367 interface device unit is created
368 (see <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
369 Note that setting this parameter might result in additional dependencies to be added to the unit (see
370 above).</para></listitem>
374 <term><varname>SocketUser=</varname></term>
375 <term><varname>SocketGroup=</varname></term>
377 <listitem><para>Takes a UNIX user/group name. When specified, all <constant>AF_UNIX</constant>
378 sockets, FIFO nodes, and message queues are owned by the specified user and group. If unset (the
379 default), the nodes are owned by the root user/group (if run in system context) or the invoking
380 user/group (if run in user context). If only a user is specified but no group, then the group is
381 derived from the user's default group.</para>
383 <xi:include href="version-info.xml" xpointer="v214"/></listitem>
387 <term><varname>SocketMode=</varname></term>
388 <listitem><para>If listening on a file system socket, FIFO, or message queue, this option specifies
389 the file system access mode used when creating the file node. Takes an access mode in octal notation.
390 Defaults to 0666.</para></listitem>
394 <term><varname>DirectoryMode=</varname></term>
395 <listitem><para>If listening on a file system socket or FIFO,
396 the parent directories are automatically created if needed.
397 This option specifies the file system access mode used when
398 creating these directories. Takes an access mode in octal
399 notation. Defaults to 0755.</para></listitem>
403 <term><varname>Accept=</varname></term>
404 <listitem><para>Takes a boolean argument. If yes, a service instance is spawned for each incoming
405 connection and only the connection socket is passed to it. If no, all listening sockets themselves
406 are passed to the started service unit, and only one service unit is spawned for all connections
407 (also see above). This value is ignored for datagram sockets and FIFOs where a single service unit
408 unconditionally handles all incoming traffic. Defaults to <option>no</option>. For performance
409 reasons, it is recommended to write new daemons only in a way that is suitable for
410 <option>Accept=no</option>. A daemon listening on an <constant>AF_UNIX</constant> socket may, but
411 does not need to, call
412 <citerefentry><refentrytitle>close</refentrytitle><manvolnum>2</manvolnum></citerefentry> on the
413 received socket before exiting. However, it must not unlink the socket from a file system. It should
415 <citerefentry><refentrytitle>shutdown</refentrytitle><manvolnum>2</manvolnum></citerefentry> on
416 sockets it got with <varname>Accept=no</varname>, but it may do so for sockets it got with
417 <varname>Accept=yes</varname> set. Setting <varname>Accept=yes</varname> is mostly useful to allow
418 daemons designed for usage with <citerefentry
419 project='freebsd'><refentrytitle>inetd</refentrytitle><manvolnum>8</manvolnum></citerefentry> to work
420 unmodified with systemd socket activation.</para>
422 <para>Note that depending on this setting the services activated by units of this type are either
423 regular services (in case of <varname>Accept=</varname><option>no</option>) or instances of templated
424 services (in case of <varname>Accept=</varname><option>yes</option>). See the Description section
425 above for a more detailed discussion of the naming rules of triggered services.</para>
427 <para>For IPv4 and IPv6 connections, the <varname>$REMOTE_ADDR</varname> environment variable will
428 contain the remote IP address, and <varname>$REMOTE_PORT</varname> will contain the remote port. This
429 is the same as the format used by CGI. For <constant>SOCK_RAW</constant>, the port is the IP
432 <para>For <constant>AF_UNIX</constant> socket connections, the <varname>$REMOTE_ADDR</varname>
433 environment variable will contain either the remote socket's file system path starting with a slash
434 (<literal>/</literal>) or its address in the abstract namespace starting with an at symbol
435 (<literal>@</literal>). If the socket is unnamed, <varname>$REMOTE_ADDR</varname> will not be set.</para>
437 <para>It is recommended to set <varname>CollectMode=inactive-or-failed</varname> for service
438 instances activated via <varname>Accept=yes</varname>, to ensure that failed connection services are
439 cleaned up and released from memory, and do not accumulate.</para></listitem>
443 <term><varname>Writable=</varname></term>
444 <listitem><para>Takes a boolean argument. May only be used in
445 conjunction with <varname>ListenSpecial=</varname>. If true,
446 the specified special file is opened in read-write mode, if
447 false, in read-only mode. Defaults to false.</para>
449 <xi:include href="version-info.xml" xpointer="v227"/></listitem>
453 <term><varname>FlushPending=</varname></term>
454 <listitem><para>Takes a boolean argument. May only be used when
455 <option>Accept=no</option>. If yes, the socket's buffers are cleared after the
456 triggered service exited. This causes any pending data to be
457 flushed and any pending incoming connections to be rejected. If no, the
458 socket's buffers will not be cleared, permitting the service to handle any
459 pending connections after restart, which is the usually expected behaviour.
460 Defaults to <option>no</option>.
463 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
467 <term><varname>MaxConnections=</varname></term>
468 <listitem><para>The maximum number of connections to simultaneously run services instances for, when
469 <option>Accept=yes</option> is set. If more concurrent connections are coming in, they will be refused
470 until at least one existing connection is terminated. This setting has no effect on sockets configured
471 with <option>Accept=no</option> or datagram sockets. Defaults to 64.</para></listitem>
475 <term><varname>MaxConnectionsPerSource=</varname></term>
476 <listitem><para>The maximum number of connections for a service per source IP address (in case of
477 IPv4/IPv6), per source CID (in case of <constant>AF_VSOCK</constant>), or source UID (in case of
478 <constant>AF_UNIX</constant>). This is very similar to the <varname>MaxConnections=</varname>
479 directive above. Defaults to 0, i.e. disabled.</para>
481 <xi:include href="version-info.xml" xpointer="v232"/>
486 <term><varname>KeepAlive=</varname></term>
487 <listitem><para>Takes a boolean argument. If true, the TCP/IP stack will send a keep alive message
488 after 2h (depending on the configuration of
489 <filename>/proc/sys/net/ipv4/tcp_keepalive_time</filename>) for all TCP streams accepted on this
490 socket. This controls the <constant>SO_KEEPALIVE</constant> socket option (see <citerefentry
491 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> and
492 the <ulink url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP Keepalive
493 HOWTO</ulink> for details.) Defaults to <option>false</option>.</para></listitem>
497 <term><varname>KeepAliveTimeSec=</varname></term>
498 <listitem><para>Takes time (in seconds) as argument. The connection needs to remain
499 idle before TCP starts sending keepalive probes. This controls the TCP_KEEPIDLE
501 <citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>
503 url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP
504 Keepalive HOWTO</ulink> for details.)
505 Default value is 7200 seconds (2 hours).</para>
507 <xi:include href="version-info.xml" xpointer="v216"/></listitem>
511 <term><varname>KeepAliveIntervalSec=</varname></term>
512 <listitem><para>Takes time (in seconds) as argument between individual keepalive probes, if the
513 socket option <constant>SO_KEEPALIVE</constant> has been set on this socket. This controls the
514 <constant>TCP_KEEPINTVL</constant> socket option (see <citerefentry
515 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> and
516 the <ulink url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP Keepalive
517 HOWTO</ulink> for details.) Default value is 75 seconds.</para>
519 <xi:include href="version-info.xml" xpointer="v216"/></listitem>
523 <term><varname>KeepAliveProbes=</varname></term>
524 <listitem><para>Takes an integer as argument. It is the number of
525 unacknowledged probes to send before considering the
526 connection dead and notifying the application layer. This
527 controls the TCP_KEEPCNT socket option (see
528 <citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>
530 url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP
531 Keepalive HOWTO</ulink> for details.) Default value is
534 <xi:include href="version-info.xml" xpointer="v216"/></listitem>
538 <term><varname>NoDelay=</varname></term>
539 <listitem><para>Takes a boolean argument. TCP Nagle's
540 algorithm works by combining a number of small outgoing
541 messages, and sending them all at once. This controls the
542 TCP_NODELAY socket option (see
543 <citerefentry project='die-net'><refentrytitle>tcp</refentrytitle><manvolnum>7</manvolnum></citerefentry>).
544 Defaults to <option>false</option>.</para>
546 <xi:include href="version-info.xml" xpointer="v216"/></listitem>
550 <term><varname>Priority=</varname></term>
551 <listitem><para>Takes an integer argument controlling the priority for all traffic sent from this
552 socket. This controls the <constant>SO_PRIORITY</constant> socket option (see <citerefentry
553 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
554 details.).</para></listitem>
558 <term><varname>DeferAcceptSec=</varname></term>
560 <listitem><para>Takes time (in seconds) as argument. If set,
561 the listening process will be awakened only when data arrives
562 on the socket, and not immediately when connection is
563 established. When this option is set, the
564 <constant>TCP_DEFER_ACCEPT</constant> socket option will be
566 <citerefentry project='die-net'><refentrytitle>tcp</refentrytitle><manvolnum>7</manvolnum></citerefentry>),
567 and the kernel will ignore initial ACK packets without any
568 data. The argument specifies the approximate amount of time
569 the kernel should wait for incoming data before falling back
570 to the normal behavior of honoring empty ACK packets. This
571 option is beneficial for protocols where the client sends the
572 data first (e.g. HTTP, in contrast to SMTP), because the
573 server process will not be woken up unnecessarily before it
577 <para>If the client also uses the
578 <constant>TCP_DEFER_ACCEPT</constant> option, the latency of
579 the initial connection may be reduced, because the kernel will
580 send data in the final packet establishing the connection (the
581 third packet in the "three-way handshake").</para>
583 <para>Disabled by default.</para>
585 <xi:include href="version-info.xml" xpointer="v216"/>
590 <term><varname>ReceiveBuffer=</varname></term>
591 <term><varname>SendBuffer=</varname></term>
592 <listitem><para>Takes an integer argument controlling the receive or send buffer sizes of this
593 socket, respectively. This controls the <constant>SO_RCVBUF</constant> and
594 <constant>SO_SNDBUF</constant> socket options (see <citerefentry
595 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
596 details.). The usual suffixes K, M, G are supported and are understood to the base of
597 1024.</para></listitem>
601 <term><varname>IPTOS=</varname></term>
602 <listitem><para>Takes an integer argument controlling the IP Type-Of-Service field for packets
603 generated from this socket. This controls the <constant>IP_TOS</constant> socket option (see
605 project='die-net'><refentrytitle>ip</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
606 details.). Either a numeric string or one of <option>low-delay</option>, <option>throughput</option>,
607 <option>reliability</option> or <option>low-cost</option> may be specified.</para></listitem>
611 <term><varname>IPTTL=</varname></term>
612 <listitem><para>Takes an integer argument controlling the IPv4 Time-To-Live/IPv6 Hop-Count field for
613 packets generated from this socket. This sets the
614 <constant>IP_TTL</constant>/<constant>IPV6_UNICAST_HOPS</constant> socket options (see <citerefentry
615 project='die-net'><refentrytitle>ip</refentrytitle><manvolnum>7</manvolnum></citerefentry> and
617 project='die-net'><refentrytitle>ipv6</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
618 details.)</para></listitem>
622 <term><varname>Mark=</varname></term>
623 <listitem><para>Takes an integer value. Controls the firewall mark of packets generated by this
624 socket. This can be used in the firewall logic to filter packets from this socket. This sets the
625 <constant>SO_MARK</constant> socket option. See <citerefentry
626 project='die-net'><refentrytitle>iptables</refentrytitle><manvolnum>8</manvolnum></citerefentry> for
627 details.</para></listitem>
631 <term><varname>ReusePort=</varname></term>
632 <listitem><para>Takes a boolean value. If true, allows multiple
633 <citerefentry><refentrytitle>bind</refentrytitle><manvolnum>2</manvolnum></citerefentry>s to this TCP
634 or UDP port. This controls the <constant>SO_REUSEPORT</constant> socket option. See <citerefentry
635 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
638 <xi:include href="version-info.xml" xpointer="v206"/></listitem>
642 <term><varname>SmackLabel=</varname></term>
643 <term><varname>SmackLabelIPIn=</varname></term>
644 <term><varname>SmackLabelIPOut=</varname></term>
645 <listitem><para>Takes a string value. Controls the extended
646 attributes <literal>security.SMACK64</literal>,
647 <literal>security.SMACK64IPIN</literal> and
648 <literal>security.SMACK64IPOUT</literal>, respectively, i.e.
649 the security label of the FIFO, or the security label for the
650 incoming or outgoing connections of the socket, respectively.
652 url="https://docs.kernel.org/admin-guide/LSM/Smack.html">Smack</ulink>
655 <xi:include href="version-info.xml" xpointer="v196"/></listitem>
659 <term><varname>SELinuxContextFromNet=</varname></term>
660 <listitem><para>Takes a boolean argument. When true, systemd
661 will attempt to figure out the SELinux label used for the
662 instantiated service from the information handed by the peer
663 over the network. Note that only the security level is used
664 from the information provided by the peer. Other parts of the
665 resulting SELinux context originate from either the target
666 binary that is effectively triggered by socket unit or from
667 the value of the <varname>SELinuxContext=</varname> option.
668 This configuration option applies only when activated service
669 is passed in single socket file descriptor, i.e. service
670 instances that have standard input connected to a socket or
671 services triggered by exactly one socket unit. Also note
672 that this option is useful only when MLS/MCS SELinux policy
673 is deployed. Defaults to
674 <literal>false</literal>. </para>
676 <xi:include href="version-info.xml" xpointer="v217"/></listitem>
680 <term><varname>PipeSize=</varname></term>
681 <listitem><para>Takes a size in bytes. Controls the pipe
682 buffer size of FIFOs configured in this socket unit. See
683 <citerefentry><refentrytitle>fcntl</refentrytitle><manvolnum>2</manvolnum></citerefentry>
684 for details. The usual suffixes K, M, G are supported and are
685 understood to the base of 1024.</para></listitem>
689 <term><varname>MessageQueueMaxMessages=</varname>,
690 <varname>MessageQueueMessageSize=</varname></term>
691 <listitem><para>These two settings take integer values and
692 control the mq_maxmsg field or the mq_msgsize field,
693 respectively, when creating the message queue. Note that
694 either none or both of these variables need to be set. See
695 <citerefentry project='die-net'><refentrytitle>mq_setattr</refentrytitle><manvolnum>3</manvolnum></citerefentry>
696 for details.</para></listitem>
700 <term><varname>FreeBind=</varname></term>
701 <listitem><para>Takes a boolean value. Controls whether the socket can be bound to non-local IP
702 addresses. This is useful to configure sockets listening on specific IP addresses before those IP
703 addresses are successfully configured on a network interface. This sets the
704 <constant>IP_FREEBIND</constant>/<constant>IPV6_FREEBIND</constant> socket option. For robustness
705 reasons it is recommended to use this option whenever you bind a socket to a specific IP
706 address. Defaults to <option>false</option>.</para></listitem>
710 <term><varname>Transparent=</varname></term>
711 <listitem><para>Takes a boolean value. Controls the
712 <constant>IP_TRANSPARENT</constant>/<constant>IPV6_TRANSPARENT</constant> socket option. Defaults to
713 <option>false</option>.</para></listitem>
717 <term><varname>Broadcast=</varname></term>
718 <listitem><para>Takes a boolean value. This controls the <constant>SO_BROADCAST</constant> socket
719 option, which allows broadcast datagrams to be sent from this socket. Defaults to
720 <option>false</option>.</para></listitem>
724 <term><varname>PassCredentials=</varname></term>
725 <listitem><para>Takes a boolean value. This controls the <constant>SO_PASSCRED</constant> socket
726 option, which allows <constant>AF_UNIX</constant> sockets to receive the credentials of the sending
727 process in an ancillary message. Defaults to <option>false</option>.</para></listitem>
731 <term><varname>PassSecurity=</varname></term>
732 <listitem><para>Takes a boolean value. This controls the <constant>SO_PASSSEC</constant> socket
733 option, which allows <constant>AF_UNIX</constant> sockets to receive the security context of the
734 sending process in an ancillary message. Defaults to <option>false</option>.</para></listitem>
738 <term><varname>PassPacketInfo=</varname></term>
739 <listitem><para>Takes a boolean value. This controls the <constant>IP_PKTINFO</constant>,
740 <constant>IPV6_RECVPKTINFO</constant>, <constant>NETLINK_PKTINFO</constant> or
741 <constant>PACKET_AUXDATA</constant> socket options, which enable reception of additional per-packet
742 metadata as ancillary message, on <constant>AF_INET</constant>, <constant>AF_INET6</constant>,
743 <constant>AF_UNIX</constant> and <constant>AF_PACKET</constant> sockets. Defaults to
744 <option>false</option>.</para>
746 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
750 <term><varname>Timestamping=</varname></term>
751 <listitem><para>Takes one of <literal>off</literal>, <literal>us</literal> (alias:
752 <literal>usec</literal>, <literal>μs</literal>) or <literal>ns</literal> (alias:
753 <literal>nsec</literal>). This controls the <constant>SO_TIMESTAMP</constant> or
754 <constant>SO_TIMESTAMPNS</constant> socket options, and enables whether ingress network traffic shall
755 carry timestamping metadata. Defaults to <option>off</option>.</para>
757 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
761 <term><varname>TCPCongestion=</varname></term>
762 <listitem><para>Takes a string value. Controls the TCP congestion algorithm used by this
763 socket. Should be one of <literal>westwood</literal>, <literal>reno</literal>,
764 <literal>cubic</literal>, <literal>lp</literal> or any other available algorithm supported by the IP
765 stack. This setting applies only to stream sockets.</para></listitem>
769 <term><varname>ExecStartPre=</varname></term>
770 <term><varname>ExecStartPost=</varname></term>
771 <listitem><para>Takes one or more command lines, which are
772 executed before or after the listening sockets/FIFOs are
773 created and bound, respectively. The first token of the
774 command line must be an absolute filename, then followed by
775 arguments for the process. Multiple command lines may be
776 specified following the same scheme as used for
777 <varname>ExecStartPre=</varname> of service unit
778 files.</para></listitem>
782 <term><varname>ExecStopPre=</varname></term>
783 <term><varname>ExecStopPost=</varname></term>
784 <listitem><para>Additional commands that are executed before
785 or after the listening sockets/FIFOs are closed and removed,
786 respectively. Multiple command lines may be specified
787 following the same scheme as used for
788 <varname>ExecStartPre=</varname> of service unit
789 files.</para></listitem>
793 <term><varname>TimeoutSec=</varname></term>
794 <listitem><para>Configures the time to wait for the commands
795 specified in <varname>ExecStartPre=</varname>,
796 <varname>ExecStartPost=</varname>,
797 <varname>ExecStopPre=</varname> and
798 <varname>ExecStopPost=</varname> to finish. If a command does
799 not exit within the configured time, the socket will be
800 considered failed and be shut down again. All commands still
801 running will be terminated forcibly via
802 <constant>SIGTERM</constant>, and after another delay of this
803 time with <constant>SIGKILL</constant>. (See
804 <option>KillMode=</option> in
805 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>.)
806 Takes a unit-less value in seconds, or a time span value such
807 as "5min 20s". Pass <literal>0</literal> to disable the
808 timeout logic. Defaults to
809 <varname>DefaultTimeoutStartSec=</varname> from the manager
810 configuration file (see
811 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
816 <term><varname>Service=</varname></term>
817 <listitem><para>Specifies the service unit name to activate on
818 incoming traffic. This setting is only allowed for sockets
819 with <varname>Accept=no</varname>. It defaults to the service
820 that bears the same name as the socket (with the suffix
821 replaced). In most cases, it should not be necessary to use
822 this option. Note that setting this parameter might result in
823 additional dependencies to be added to the unit (see
824 above).</para></listitem>
828 <term><varname>RemoveOnStop=</varname></term>
829 <listitem><para>Takes a boolean argument. If enabled, any file nodes created by this socket unit are
830 removed when it is stopped. This applies to <constant>AF_UNIX</constant> sockets in the file system,
831 POSIX message queues, FIFOs, as well as any symlinks to them configured with
832 <varname>Symlinks=</varname>. Normally, it should not be necessary to use this option, and is not
833 recommended as services might continue to run after the socket unit has been terminated and it should
834 still be possible to communicate with them via their file system node. Defaults to
837 <xi:include href="version-info.xml" xpointer="v214"/></listitem>
841 <term><varname>Symlinks=</varname></term>
842 <listitem><para>Takes a list of file system paths. The specified paths will be created as symlinks to the
843 <constant>AF_UNIX</constant> socket path or FIFO path of this socket unit. If this setting is used, only one
844 <constant>AF_UNIX</constant> socket in the file system or one FIFO may be configured for the socket unit. Use
845 this option to manage one or more symlinked alias names for a socket, binding their lifecycle together. Note
846 that if creation of a symlink fails this is not considered fatal for the socket unit, and the socket unit may
847 still start. If an empty string is assigned, the list of paths is reset. Defaults to an empty
850 <xi:include href="version-info.xml" xpointer="v214"/></listitem>
854 <term><varname>FileDescriptorName=</varname></term>
855 <listitem><para>Assigns a name to all file descriptors this socket unit encapsulates.
856 This is useful to help activated services identify specific file descriptors, if multiple fds are passed.
858 <citerefentry><refentrytitle>sd_listen_fds_with_names</refentrytitle><manvolnum>3</manvolnum></citerefentry>
859 call to acquire the names configured for the received file descriptors. Names may contain any ASCII character,
860 but must exclude control characters and <literal>:</literal>, and must be at most 255 characters in length.
861 If this setting is not used, the file descriptor name defaults to the name of the socket unit
862 (including its <filename>.socket</filename> suffix) when <varname>Accept=no</varname>,
863 <literal>connection</literal> otherwise.</para>
865 <xi:include href="version-info.xml" xpointer="v227"/></listitem>
869 <term><varname>TriggerLimitIntervalSec=</varname></term>
870 <term><varname>TriggerLimitBurst=</varname></term>
872 <listitem><para>Configures a limit on how often this socket unit may be activated within a specific
873 time interval. The <varname>TriggerLimitIntervalSec=</varname> setting may be used to configure the
874 length of the time interval in the usual time units <literal>us</literal>, <literal>ms</literal>,
875 <literal>s</literal>, <literal>min</literal>, <literal>h</literal>, … and defaults to 2s (See
876 <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
877 details on the various time units understood). The <varname>TriggerLimitBurst=</varname> setting
878 takes a positive integer value and specifies the number of permitted activations per time interval,
879 and defaults to 200 for <varname>Accept=yes</varname> sockets (thus by default permitting 200
880 activations per 2s), and 20 otherwise (20 activations per 2s). Set either to 0 to disable any form of
881 trigger rate limiting.</para>
883 <para>If the limit is hit, the socket unit is placed into a failure mode, and will not be connectible
884 anymore until restarted. Note that this limit is enforced before the service activation is
887 <para>Compare with <varname>PollLimitIntervalSec=</varname>/<varname>PollLimitBurst=</varname>
888 described below, which implements a temporary slowdown if a socket unit is flooded with incoming
889 traffic, as opposed to the permanent failure state
890 <varname>TriggerLimitIntervalSec=</varname>/<varname>TriggerLimitBurst=</varname> results in.</para>
892 <xi:include href="version-info.xml" xpointer="v230"/></listitem>
896 <term><varname>PollLimitIntervalSec=</varname></term>
897 <term><varname>PollLimitBurst=</varname></term>
899 <listitem><para>Configures a limit on how often polling events on the file descriptors backing this
900 socket unit will be considered. This pair of settings is similar to
901 <varname>TriggerLimitIntervalSec=</varname>/<varname>TriggerLimitBurst=</varname> but instead of
902 putting a (fatal) limit on the activation frequency puts a (transient) limit on the polling
903 frequency. The expected parameter syntax and range are identical to that of the aforementioned
904 options, and can be disabled the same way.</para>
906 <para>If the polling limit is hit polling is temporarily disabled on it until the specified time
907 window passes. The polling limit hence slows down connection attempts if hit, but unlike the trigger
908 limit will not cause permanent failures. It's the recommended mechanism to deal with DoS attempts
909 through packet flooding.</para>
911 <para>The polling limit is enforced per file descriptor to listen on, as opposed to the trigger limit
912 which is enforced for the entire socket unit. This distinction matters for socket units that listen
913 on multiple file descriptors (i.e. have multiple <varname>ListenXYZ=</varname> stanzas).</para>
915 <para>These setting defaults to 150 (in case of <varname>Accept=yes</varname>) and 15 (otherwise)
916 polling events per 2s. This is considerably lower than the default values for the trigger limit (see
917 above) and means that the polling limit should typically ensure the trigger limit is never hit,
918 unless one of them is reconfigured or disabled.</para>
920 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
924 <term><varname>PassFileDescriptorsToExec=</varname></term>
926 <listitem><para>Takes a boolean argument. Defaults to off. If enabled, file descriptors created by
927 the socket unit are passed to <varname>ExecStartPost=</varname>, <varname>ExecStopPre=</varname>, and
928 <varname>ExecStopPost=</varname> commands from the socket unit. The passed file descriptors can be
930 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry> as
931 if the commands were invoked from the associated service units. Note that
932 <varname>ExecStartPre=</varname> command cannot access socket file descriptors.</para>
934 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
939 <xi:include href="systemd.service.xml" xpointer="shared-unit-options" />
943 <title>See Also</title>
944 <para><simplelist type="inline">
945 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
946 <member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
947 <member><citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
948 <member><citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
949 <member><citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
950 <member><citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
951 <member><citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
952 <member><citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
953 <member><citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
954 <member><citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
955 <member><citerefentry><refentrytitle>sd_listen_fds_with_names</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
958 For more extensive descriptions see the "systemd for Developers" series:
959 <simplelist type="inline">
960 <member><ulink url="https://0pointer.de/blog/projects/socket-activation.html">Socket Activation</ulink></member>
961 <member><ulink url="https://0pointer.de/blog/projects/socket-activation2.html">Socket Activation, part II</ulink></member>
962 <member><ulink url="https://0pointer.de/blog/projects/inetd.html">Converting inetd Services</ulink></member>
963 <member><ulink url="https://0pointer.de/blog/projects/socket-activated-containers.html">Socket Activated Internet Services and OS Containers</ulink></member>