hostnamectl ‐ #system - five4nets/Linux-Knowledgebase GitHub Wiki

🖥️ Linux hostnamectl Command Tutorial

The hostnamectl command is a systemd utility used to view and modify the system hostname and related metadata. It provides a consistent interface for managing hostnames across modern Linux distributions.


📋 Basic Syntax

hostnamectl [OPTIONS...] [COMMAND]
  • COMMAND: Action to perform (e.g., status, set-hostname)
  • OPTIONS: Flags to modify behavior (e.g., --static, --pretty)

🧠 Types of Hostnames

Type Description
Static Persistent hostname set by the system administrator
Transient Temporary hostname assigned by DHCP or mDNS
Pretty A user-friendly name with spaces and special characters

🔧 Common Commands

1. Show Current Hostname and System Info

hostnamectl

2. Set a New Static Hostname

sudo hostnamectl set-hostname my-server

3. Set a Pretty Hostname

sudo hostnamectl set-hostname "My Personal Laptop" --pretty

4. Set a Transient Hostname

sudo hostnamectl set-hostname temp-host --transient

5. Set All Hostname Types at Once

sudo hostnamectl set-hostname "devbox.local"
sudo hostnamectl set-hostname "Developer Workstation" --pretty

6. View Only the Static Hostname

hostnamectl --static

7. Change Hostname on a Remote Machine

sudo hostnamectl set-hostname server3 -H [email protected]

🧪 Example Output

Static hostname: devbox.local
Pretty hostname: Developer Workstation
Transient hostname: devbox.local
Icon name: computer-laptop
Chassis: laptop
Operating System: Ubuntu 22.04 LTS
Kernel: Linux 5.15.0-91-generic
Architecture: x86-64

🧭 Tips

  • Changes to the static hostname persist across reboots.
  • Use hostnamectl status to explicitly show current settings.
  • Combine with --static, --pretty, or --transient to target specific hostname types.

📚 References


Happy hostname hacking! 🧑‍💻


Let me know if you'd like a version that includes scripting examples or integrates with cloud-init for automated deployments!