The systemd-networkd service failed to start because it couldn’t acquire the CAP_NET_ADMIN capability, which it needs to manage network interfaces and configurations.
Common Causes and Fixes
-
Incorrect
CAP_NET_ADMINConfiguration insystemd-networkdUnit File:- Diagnosis: Inspect the
systemd-networkdservice unit file, typically located at/usr/lib/systemd/system/systemd-networkd.serviceor/etc/systemd/system/systemd-networkd.service. Look for lines related to capabilities. If you seeCapabilityBoundingSet=CAP_NET_RAWor similar, it’s missingCAP_NET_ADMIN. - Fix: Add
CAP_NET_ADMINto theCapabilityBoundingSet=directive. If the line doesn’t exist, create it. In/etc/systemd/system/systemd-networkd.service.d/override.conf(or directly in the main unit file if you prefer), add:
(Note: The exact list of capabilities might vary slightly based on your systemd version and distribution, but[Service] CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_SETUID CAP_SETGID CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_KILL CAP_SYS_CHROOT CAP_AUDIT_WRITE CAP_GROUP_SU_ID CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SETFCAP CAP_SETUID CAP_SYS_CHROOT CAP_SYS_MODULE CAP_SYS_PTRACE CAP_SYS_RAWIO CAP_SYS_TIME CAP_SYS_TTY_CONFIGCAP_NET_ADMINis the critical one here. The provided list is a common, comprehensive set for network-related services. You can also explicitly addCAP_NET_ADMINtoAmbientCapabilities=if you want it to be effective even after dropping privileges.) - Why it works:
CapabilityBoundingSetrestricts the capabilities a service can ever gain. By explicitly includingCAP_NET_ADMINin this set, you allowsystemd-networkdto request and use this specific privilege, which is essential for its network management tasks.
- Diagnosis: Inspect the
-
Security Module (SELinux/AppArmor) Restrictions:
- Diagnosis: Check system logs for SELinux or AppArmor denials related to
systemd-networkd. For SELinux, usesudo ausearch -m avc -ts recent. For AppArmor, checksudo dmesg | grep -i apparmoror/var/log/audit/audit.log. Look for messages indicatingsystemd-networkdis deniedsetcaporcap_net_adminoperations. - Fix (SELinux): If SELinux is the culprit, you might need to adjust its policy. A common workaround (though not always ideal for production) is to set permissive mode temporarily:
sudo setenforce 0. For a more permanent fix, you’d need to create or modify an SELinux policy module. A simpler approach might be to ensure thenetworkd_manage_etc_filesboolean is enabled if applicable, or to explicitly grant the capability:
(This command associates thesudo semanage fcap -a -t cap_net_admin_t -f /usr/lib/systemd/systemd-networkdcap_net_admincapability with thesystemd-networkdexecutable. You might need to installpolicycoreutils-python-utilsforsemanage.) - Fix (AppArmor): If AppArmor is blocking it, you might find a profile for
systemd-networkdin/etc/apparmor.d/. You can edit the profile to allow the necessary operations. For example, you might need to add a line like:
Then reload AppArmor:capability net_admin,sudo systemctl reload apparmor. - Why it works: Security modules enforce granular access controls. If SELinux or AppArmor incorrectly assumes
systemd-networkdshouldn’t haveCAP_NET_ADMIN, they will block it. Adjusting the security policy or temporarily relaxing it allowssystemd-networkdto obtain the capability.
- Diagnosis: Check system logs for SELinux or AppArmor denials related to
-
Container/Virtualization Environment Limitations:
- Diagnosis: If
systemd-networkdis running inside a container (e.g., Docker, LXC) or a heavily sandboxed environment, the container runtime or hypervisor might be preventing the process from acquiring elevated capabilities. Check the container’s runtime configuration or documentation. - Fix: When running the container, ensure it has sufficient privileges. For Docker, this might involve using the
--cap-add=NET_ADMINflag:
For LXC, you might need to adjust thedocker run --cap-add=NET_ADMIN ... your_image ...lxc.cap.keeporlxc.cap.effectivesettings in the container’s configuration file. - Why it works: Container runtimes and virtualization platforms often isolate processes by default. Explicitly granting
NET_ADMINcapability to the container process allowssystemd-networkdwithin the container to perform its network operations.
- Diagnosis: If
-
Systemd Version or Distribution-Specific Defaults:
- Diagnosis: Older versions of
systemdor specific Linux distributions might have different default capability settings or security hardening applied tosystemd-networkd. Consult the release notes or documentation for your specificsystemdversion and distribution. - Fix: This often ties back to Cause 1. You might need to manually add
CAP_NET_ADMINto theCapabilityBoundingSetorAmbientCapabilitiesin thesystemd-networkd.serviceunit file, as newer versions might have tightened defaults, or older ones might not have had it enabled by default. - Why it works: Explicitly defining the required capabilities in the service unit file overrides any potentially restrictive or missing defaults from the systemd version or distribution configuration.
- Diagnosis: Older versions of
-
Filesystem Mount Options (
noexec,nosuid,nodev):- Diagnosis: While less common for the executable itself, if the filesystem where
systemd-networkdresides (or where it needs to write temporary files or socket files) is mounted with restrictive options likenoexec(prevents execution), it could theoretically interfere, thoughCAP_NET_ADMINis more about process privileges than filesystem execution. More relevantly, if/procor/sysare mounted with unusual options that restrict access to kernel interfaces, this could be an issue. Checkmountoutput for/and/proc,/sys. - Fix: Ensure that critical system filesystems, especially
/procand/sys, are mounted with standard options that allow kernel interface access./procshould typically not havehidepidorread-only, and/sysshould not beroifsystemd-networkdneeds to write to it (which it does for network configuration). Edit/etc/fstaband remount if necessary (e.g.,sudo mount -o remount,rw /sys). - Why it works:
CAP_NET_ADMINoperations often involve direct interaction with the kernel via/procand/sysinterfaces. Restrictive mount options on these virtual filesystems can preventsystemd-networkdfrom successfully communicating with the kernel to perform network configuration, even if it technically has the capability.
- Diagnosis: While less common for the executable itself, if the filesystem where
-
External Tools Interfering with Capabilities:
- Diagnosis: If you have other tools that manage network capabilities or security contexts (e.g., custom init scripts, other network managers) that might be running concurrently or have modified system defaults, they could be stripping capabilities or interfering. Check
ps auxZ | grep systemd-networkdfor SELinux contexts oraa-statusfor AppArmor. - Fix: Ensure that no other process is actively trying to manage
systemd-networkd’s capabilities. If you are using multiple network management tools, disable all but one. If custom scripts are involved, review them for anysetcapor capability manipulation commands that might affectsystemd-networkd. - Why it works: Capabilities are a fine-grained privilege system. If another process or configuration is actively removing or overriding the capabilities assigned to
systemd-networkd, it will lose the necessary permissions.
- Diagnosis: If you have other tools that manage network capabilities or security contexts (e.g., custom init scripts, other network managers) that might be running concurrently or have modified system defaults, they could be stripping capabilities or interfering. Check
After fixing the CAP_NET_ADMIN issue, you might encounter a "Failed to read network configuration" error if your .network files in /etc/systemd/network/ are malformed or missing.