Why systemd ProtectHostname=yes Broke udev Scripts After Host Rename
The Symptom
Automated disk replacement worked fine on most nodes in a Linux storage cluster, yet failed mysteriously on a handful of hosts. Worse, the caller script swallowed the non-zero return status and reported success anyway.
Comparing working and failing nodes revealed one subtle difference: the failing nodes had been renamed after initial boot without a reboot.
Tracing the UTS Namespace
Since systemd >= 242, systemd-udevd.service ships with ProtectHostname=yes enabled by default. Under the hood, systemd runs udevd inside its own isolated UTS namespace, freezing the hostname to whatever it was when the daemon started (localhost).
I verified this live on an affected node by entering udevd’s UTS namespace directly:
UDEV_PID=$(pidof systemd-udevd)
hostname # returns the new hostname
nsenter -t "$UDEV_PID" -u hostname # still returns "localhost"
Every udev-triggered script inherited udevd’s stale namespace, so hostname lookups inside the auto-replacement hook resolved to localhost and targeted the wrong node identity. Along the way, we also discovered an earlier workaround in the codebase was completely ineffective.
Resolution
- Added a clean systemd drop-in override (
ProtectHostname=no) where udev hooks legitimately require live hostname resolution, or read the authoritative cluster node identity instead of relying on transient UTS state. - Replaced silent error swallowing in the caller with fail-loud validation so future mismatches surface immediately.
Enjoyed this note or seen a similar bug?
Feel free to drop a line—always glad to exchange ideas with fellow engineers.