Change the Hostname with hostnamectl
hostnamectl sets the static, transient, and pretty hostname in one step on systemd distros, no reboot required.
01Command
$ sudo hostnamectl set-hostname new-name02What 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
04Undo
$ sudo hostnamectl set-hostname old-name05Sources
- hostnamectl(1) - Linux manual pageEvidence: 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
timedatectl lists, sets, and verifies the system timezone and NTP sync status on systemd distributions.
systemctl list-timers shows every scheduled timer unit with its last and next run times, which many users forget replaces cron on modern distros.
systemctl cat reveals a service's unit file plus every drop-in override; systemctl edit creates overrides without touching vendor files.