System and processes

The hostnamectl command

Shows and changes the machine's name and basic hardware data known to systemd: operating system, kernel, architecture and chassis type. It is systemd's tool for the machine name, and it saves changes permanently. It works on any machine running systemd, with or without a desktop.

Syntax

hostnamectl [opciones] [comando]Try it in the terminal →

Most useful options

--staticShows the static name, the one stored in /etc/hostname
--prettyShows the pretty name, which allows spaces and capital letters
--transientShows the transient name, the one the kernel has at that moment
set-hostname <nombre>Changes the name. It needs root and is saved permanently
set-chassis <tipo>Sets the machine type: desktop, laptop, server, vm, container...

Copy-ready examples

$ hostnamectlfull record of the machine: name, operating system, kernel and architecture.

Example output

 Static hostname: servidor-web
       Icon name: computer-server
         Chassis: server
      Machine ID: 5d8c4e1b7a2f4c09b3e6d1f0a9c8b7e6
         Boot ID: 9a2b7f10c3d84e5a8b1f6c2d0e9a4b77
Operating System: Ubuntu 24.04.1 LTS
          Kernel: Linux 6.8.0-45-generic
    Architecture: x86-64
$ hostnamectl --staticonly the static name, useful inside a script.

Example output

servidor-web
$ sudo hostnamectl set-hostname servidor-webchanges the machine name permanently. New programs see it; those already running keep the old one.
$ sudo hostnamectl set-chassis laptopmarks the machine as a laptop. Some desktops and tools use it to choose icons and profiles.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
System has not been booted with systemd as init system (PID 1). Can't operate.The system does not use systemd as its init process: this happens in some Docker containers and in WSL without systemd enabled.Use hostname for a temporary change, or edit /etc/hostname and /etc/hosts by hand.

Typical mistakes

  • The static name must be valid as a network name (letters, digits and hyphens). The pretty name can have spaces and accents.
  • A change does not reach programs already running: restart the services that store the name, or the machine.

Differences from similar commands

  • hostname: shows or changes only the machine name, with no system data. It works without systemd.
  • uname: shows kernel and architecture data, but cannot change anything.
  • localectl: does the same for the system language and the keyboard layout.
  • timedatectl: does the same for the date, time zone and NTP synchronization.

Related commands

FAQ

What is the difference between hostname and hostnamectl?

hostname changes the name only until the next boot. hostnamectl saves it permanently and shows system data.

Do I need root to see the name?

No. Viewing the name and the data works without root. Only changes, such as set-hostname, need sudo.

What is the Machine ID?

A unique identifier for the installation, stored in /etc/machine-id. systemd and some services use it, and it does not change when you rename the machine.

Where is the name stored?

In /etc/hostname, which is the static name. Matches for the network also appear in /etc/hosts.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course