Update a Linux hostname to match a new naming convention using
hostnamectl
and confirm the change through system status and config files. Validate the runtime and persistent hostname state and ensure the local resolver mapping aligns with the new name.
Your company recently restructured its internal network. You’ve been asked to update hostnames to reflect new node naming conventions. The current hostname is old-server and it must be changed to web-node01 .
Hostnames show up everywhere: monitoring dashboards, SSH prompts, log records, certificates, and inventory systems. A correct hostname change is both runtime-correct and persistent across reboots.
hostnamectl
.
web-node01
.
hostnamectl
.
/etc/hostname
.
/etc/hosts
reflects the new hostname.
hostnamectl
and understanding static vs transient hostname.
hostnamectl set-hostname
.
/etc/hostname
.
/etc/hosts
(common in VM images and default distro setups).
hostnamectl
This provides a structured view of hostname state and platform metadata. The key field for this lab is the static hostname, which persists across reboot.
Static hostname: old-server
Icon name: computer-vm
Chassis: vm
Machine ID: a1b2c3d4e5f6g7h8i9j0
Boot ID: x1y2z3a4b5c6d7e8f9g0
Operating System: Ubuntu 22.04.4 LTS
Kernel: Linux 5.15.0-88-generic
Architecture: x86-64
sudo hostnamectl set-hostname web-node01
This updates the static hostname persistently. You will typically see the prompt change
in new sessions and the hostname reflected immediately in
hostnamectl
output.
Hostname successfully changed.
hostnamectl
This confirms runtime state and verifies that the persistent static hostname now matches the expected value.
Static hostname: web-node01
Icon name: computer-vm
Chassis: vm
Machine ID: a1b2c3d4e5f6g7h8i9j0
Boot ID: x1y2z3a4b5c6d7e8f9g0
Operating System: Ubuntu 22.04.4 LTS
Kernel: Linux 5.15.0-88-generic
Architecture: x86-64
cat /etc/hostname
This is the simplest proof that the hostname change is persistent on systems that store the hostname in this file. The value should match the static hostname.
web-node01
cat /etc/hosts
Many systems map the local hostname in
/etc/hosts
(commonly to
127.0.1.1
on Ubuntu-style defaults). If this mapping is wrong, local name resolution can behave unexpectedly,
and some services may log confusing host identifiers.
127.0.0.1 localhost
127.0.1.1 web-node01
hostnamectl
: Displays and manages system hostname settings via systemd-hostnamed.
hostnamectl set-hostname <name>
: Sets the static hostname persistently.
<name>
: The new node hostname (for example
web-node01
).
/etc/hostname
: File storing the persistent hostname on many Linux distributions.
/etc/hosts
: Local name resolution mapping file, often used to bind the hostname to loopback
for predictable local resolution.