Change Hostname on Linux (Ubuntu, Debian, CentOS, Fedora, Arch)
This post shows safe, distro-agnostic ways to change the system hostname and covers common variations (systemd, init-based, NetworkManager, cloud-init, and containers). Quick summary Temporary (current session): sudo hostname <new> Persistent (systemd systems): sudo hostnamectl set-hostname <new> Also update /etc/hosts and check cloud-init if present. Important: Always verify whether your environment (cloud image, container, or managed host) uses cloud-init or another management tool — it may overwrite manual changes. 1 — systemd-based systems (Ubuntu, Debian, Fedora, Arch, CentOS 7+) Set the persistent hostname: ...