How to Fix ‘Failed to Start Hostname Service’ in Ubuntu

Attempting to query or change your system hostname on an Ubuntu desktop or server using hostnamectl only to receive errors such as “Could not set property: Failed to activate service ‘org.freedesktop.hostname1’: timed out” or finding systemd logs reporting “Failed to start Hostname Service (systemd-hostnamed.service)” halts system identity management.

The systemd-hostnamed.service is a small system service managed by systemd that dynamically updates the system hostname, machine information, and icon names via D-Bus IPC. When this unit fails to spawn or times out, the causes typically include a masked unit file, D-Bus system message bus deadlocks, syntax mismatches between /etc/hostname and /etc/hosts, or file permission locks.

Failure Point Technical Root Cause Targeted Solution
Masked systemd-hostnamed Unit Unit file symlinked to /dev/null by server hardening scripts Unmask systemd-hostnamed.service via systemctl
D-Bus IPC Socket Timeout dbus-daemon or dbus-broker deadlocked or unable to allocate sockets Restart dbus.service and reload systemd daemon
Desynchronised /etc/hosts and /etc/hostname Primary hostname lacks matching 127.0.1.1 loopback resolution entry Align entries in /etc/hosts and /etc/hostname
Read-Only Root Filesystem Filesystem errors cause kernel to mount root volume as read-only Check filesystem health and remount volume as read-write

Method 1: Check Unit Status and Unmask the Service

Server hardening scripts, minimal container templates, or security templates frequently mask systemd-hostnamed.service by linking it to /dev/null, preventing systemd from activating it on demand.

  1. Open a terminal shell.
  2. Inspect the operational state of the service:
    sudo systemctl status systemd-hostnamed.service
  3. If the output states Loaded: masked (Reason: Unit systemd-hostnamed.service is masked), unmask the service immediately:
    sudo systemctl unmask systemd-hostnamed.service
  4. Enable and start the service:
    sudo systemctl enable systemd-hostnamed.service
    sudo systemctl start systemd-hostnamed.service
  5. Verify that the status changes to Active: active (running).

Method 2: Verify and Align /etc/hostname and /etc/hosts

If the hostname declared in /etc/hostname does not resolve to the local loopback address in /etc/hosts, D-Bus and systemd services experience prolonged 25-second timeout delays.

  1. Check your active configured hostname:
    cat /etc/hostname
    (Example: ubuntuserver)
  2. Open the hosts file in a text editor:
    sudo nano /etc/hosts
  3. Ensure that both local loopback addresses exist and match your hostname exactly:
    127.0.0.1   localhost
    127.0.1.1   ubuntuserver
  4. Press Ctrl + O to save, press Enter, and press Ctrl + X to exit.
  5. Test hostname queries again:
    hostnamectl status

Method 3: Restart D-Bus and Reload Systemd Daemon

Because systemd-hostnamed is activated on demand via D-Bus activation, a stalled D-Bus system daemon prevents client applications from communicating with the hostname broker.

  1. Reload the systemd manager configuration:
    sudo systemctl daemon-reload
  2. Restart the Hostname service explicitly:
    sudo systemctl restart systemd-hostnamed.service
  3. If D-Bus communications remain stalled, restart the system message bus daemon:
    sudo systemctl restart dbus.service
    (Caution: Restarting D-Bus in a desktop session may disconnect graphical login sessions; recommended over SSH or TTY).
  4. Verify service responsiveness with:
    hostnamectl

Method 4: Inspect Detailed systemd Journal Logs

If the service starts and immediately crashes (entering a crash-loop), querying journalctl reveals internal assertion failures.

  1. Query the service journal logs:
    sudo journalctl -xeu systemd-hostnamed.service --no-pager -n 50
  2. Look for error messages such as:
    • Failed to set hostname: Read-only file system (indicates drive mount protection).
    • Failed to register name: Connection timed out (indicates socket blockage).

Method 5: Verify Permissions on Configuration Files

The hostname service requires read and write permissions to update /etc/hostname and machine metadata files.

  1. Check file permissions on the hostname file:
    ls -l /etc/hostname
  2. The file should be owned by root:root with permissions set to 644 (-rw-r--r--).
  3. If permissions were altered, restore them:
    sudo chown root:root /etc/hostname
    sudo chmod 644 /etc/hostname
  4. Restart the service:
    sudo systemctl restart systemd-hostnamed

Preventing Hostname Service Deadlocks in Cloud Environments

If running Ubuntu inside cloud platforms (AWS, Azure, DigitalOcean) managed by cloud-init, ensure that cloud provisioning scripts do not simultaneously attempt to write to /etc/hostname while systemd-hostnamed is active. Setting preserve_hostname: true inside /etc/cloud/cloud.cfg prevents cloud-init from overwriting custom hostname parameters during reboot.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.