How to Use the hostnamectl Command in Linux to Change System Hostname and Deployment Metadata

In modern systemd-based Linux distributions, configuring a server or workstation identifier involves more than manually editing /etc/hostname. The systemd suite provides hostnamectl as a dedicated management utility to query and configure three distinct classes of hostnames, hardware chassis classifications, and deployment environment metadata. Using hostnamectl ensures that changes are propagated dynamically across network daemons, mDNS discovery services, and local resolver caches without requiring a system reboot.

Understanding the Three Distinct Hostname Classes in Linux

The Linux kernel and systemd distinguish between three specific hostname types:

  • Static Hostname: The traditional persistent identifier stored in /etc/hostname. It is assigned during system initialization and read by services upon boot.
  • Transient Hostname: A dynamic fallback identifier maintained in kernel memory. If a static hostname is not defined, network configuration tools (such as DHCP servers or mDNS) assign the transient name temporarily during network lease renewal.
  • Pretty Hostname: A high-level, human-friendly UTF-8 description that may include spaces, capitalisation, punctuation, and special characters (e.g., Production Web Node #04). It is displayed in desktop interface settings and network management consoles.

Inspecting Current Hostname and Architecture Metadata

To inspect your current configuration, execute the command without additional arguments:

hostnamectl

The terminal outputs a comprehensive overview of system identification parameters:

 Static hostname: web-server-node-01
       Icon name: computer-vm
         Chassis: vm
  Deployment env: production
Operating System: Ubuntu 24.04 LTS
          Kernel: Linux 6.8.0-31-generic
    Architecture: x86-64
 Hardware Vendor: VMware, Inc.

Setting the Static and Transient Hostname

To change the primary system hostname persistently, use the set-hostname subcommand with root privileges:

sudo hostnamectl set-hostname node-worker-prod-02

By default, this command sets both the static and transient hostnames simultaneously. It automatically overwrites /etc/hostname and calls the kernel sethostname() system call.

To explicitly target only the static or transient hostname independently, pass the appropriate flag:

sudo hostnamectl set-hostname --static node-worker-prod-02
sudo hostnamectl set-hostname --transient temp-dhcp-node

Configuring a Pretty Hostname for Desktop and MDM Visibility

To provide a descriptive, human-readable name for monitoring dashboards or local users, assign a pretty hostname using quotes:

sudo hostnamectl set-hostname --pretty "Primary Edge Gateway (Frankfurt DC)"

This setting is stored as the PRETTY_HOSTNAME key inside /etc/machine-info.

Setting the System Chassis Type and Deployment Environment

System monitoring platforms, inventory automation scripts, and GUI desktops use chassis metadata to select appropriate interface icons and power profiles. You can define the hardware chassis explicitly:

sudo hostnamectl chassis server

Recognised chassis types include: desktop, laptop, server, tablet, handset, watch, embedded, vm, and container.

To specify whether the node belongs to a development, staging, or production infrastructure tier, set the deployment environment:

sudo hostnamectl deployment production

Valid environment identifiers include: development, integration, staging, and production.

Updating the Local /etc/hosts File

While hostnamectl updates /etc/hostname and the running kernel, local applications often resolve the machine’s name through /etc/hosts. If you change your static hostname, ensure the local loopback entry matches:

  1. Open the file with administrative privileges: sudo nano /etc/hosts.
  2. Locate the 127.0.1.1 (Debian/Ubuntu) or 127.0.0.1 line.
  3. Replace the old hostname with your new static identifier.
  4. Save and exit the editor.

Quick hostnamectl Parameter Reference

Command Option Configuration Effect
hostnamectl status Shows full system identification, kernel, and chassis details.
hostnamectl set-hostname [name] Assigns persistent static and transient hostnames.
hostnamectl set-hostname --pretty "[name]" Sets a formatted UTF-8 descriptive name in machine-info.
hostnamectl chassis [type] Defines physical or virtual chassis form factor.
hostnamectl deployment [env] Declares infrastructure deployment tier (e.g., production).
hostnamectl location "[desc]" Records geographical or rack-level equipment location.

Get the best tech tips delivered straight to your inbox.

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