🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

💡 Systemd & Services March 17, 2026 7

Linux Command: hostnamectl

Control system hostname

Terminal — Systemd & Services
Command
$ hostnamectl
Output
Shows hostname, OS, kernel, and architecture.

hostnamectl manages the system hostname. It can set the static hostname (persistent), the pretty hostname (UTF-8 descriptive name), and the transient hostname (temporary). hostnamectl is the systemd way to manage hostnames, replacing manual editing of /etc/hostname. Changes are permanent and take effect immediately. hostnamectl also shows useful system information including the machine ID, boot ID, operating system, kernel, and architecture.

Syntax

hostnamectl [COMMAND]

Common Examples

  • hostnamectl — Shows hostname, OS, kernel, and architecture.
  • sudo hostnamectl set-hostname production-web-01 — Permanently changes the hostname.
  • sudo hostnamectl set-hostname "Production Web Server 01" --pretty — Sets a descriptive name (can include spaces and special characters).
  • sudo hostnamectl set-hostname newname && sudo sed -i "s/oldname/newname/g" /etc/hosts — Changes hostname and updates /etc/hosts to match.

Pro Tips

    Master this and 230+ other Linux commands with our comprehensive eBooks and cheat sheets.

    Share this tip