« Back to Settings for systemd units

RestrictAddressFamilies setting

The property RestrictAddressFamilies is a systemd unit setting used for sandboxing. It is available since systemd 211.

Purpose: control what socket address families can be used by a unit

Why and when to use RestrictAddressFamilies

The setting RestrictAddressFamilies aims to restrict what socket address families can be used. When using it, the default is that it is used as an allow-list and define what address families can be used.

Settings

When this setting is not configured, there are no restrictions to what address families can be used.

Setting the value to none will block all address families.

To block specific address families only, a ~ can be used to turn the allow-list into a deny-list.

Caveats

This setting does not have effect on hardware platforms like:

  • 32-bit x86
  • s390 / s390x
  • mips / mips-le
  • ppc / ppc-le / ppc64/ ppc64-le

This setting does also not have effect on sockets created using alternative methods, including the systemd socket unit type or those created with the syscall socketpair(2).

Generic advice

Services that use networking functionality typically use AF_INET (IPv4) and AF_INET6 (IPv6). Using the address family AF_UNIX is suggested, as it may be used for local communication between services, including the usage of syslog syscall.

It is advised to use SystemCallArchitectures=native in combination with this setting, to prevent easy circumvention of the restrictions.

Example

A common combination might look like this.

[Service]
SystemCallArchitectures=native
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX

Values

Systemd unit setting RestrictAddressFamilies expects a boolean (yes/no or true/false) or string value.

Values for systemd unit setting RestrictAddressFamilies
ValueIntended actionAvailable since
systemd version
noneall socket address families will be blocked
[LIST OF FAMILIES]socket address families listed will be allowed

Example to show the current value of RestrictAddressFamilies for the ssh service:

systemctl show --property=RestrictAddressFamilies ssh.service

Related hardening profiles

The systemd unit setting RestrictAddressFamilies is used in the following hardening profiles.

Frequently Asked Questions

How to use systemctl edit?

Run systemctl with the 'edit' subcommand and service.

systemctl edit UNIT.service

See full answer at How to use systemctl edit to change a service?

Related articles

Like to learn more? Here is a list of articles within the same category or having similar tags.

Feedback

Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

Mastodon icon