Change the Hostname with hostnamectl

hostnamectl sets the static, transient, and pretty hostname in one step on systemd distros, no reboot required.

LinuxhostnamesystemdhostnamectlMedium risk
Run `sudo hostnamectl set-hostname new-name` to change the hostname permanently.

01Command

Command
$ sudo hostnamectl set-hostname new-name

02What it does

hostnamectl applies the change immediately and persists it across reboots, replacing manual edits to /etc/hostname. Also update /etc/hosts (the 127.0.1.1 line on Debian/Ubuntu) so sudo stops printing 'unable to resolve host' warnings, and start a new shell for the prompt to show the new name. Use `hostnamectl status` to see all three hostname classes.

03Risk

RiskMedium risk
Requirementssystemd-based distribution

04Undo

Undo
$ sudo hostnamectl set-hostname old-name

05Sources

  • hostnamectl(1) - Linux manual page
    Ubuntu Manpages · technical · 2026-09-17
    Evidence: hostnamectl set-hostname updates the hostname file and broadcasts the change to the system, applying it without a reboot.

Last verified: 2026-09-17 · Category: System & Settings

06Related solutions