Checking and Changing the Hostname
This article explains how to check and change the hostname on Ubuntu 26.04 LTS Server. There are two ways to change the hostname: a permanent method that survives a reboot, and a temporary method that reverts after a reboot.
Checking the Hostname (hostnamectl Command)
hostnamectlkazu@ubuntu2604:~$ hostnamectl
Static hostname: ubuntu2604
Icon name: computer-vm
Chassis: vm 🖴
Machine ID: 4a8cf9d0938b433e8fb26a71d7d266a7
Boot ID: b37517594817444bbfa955abceb52cd2
Virtualization: kvm
Operating System: Ubuntu 26.04 LTS
Kernel: Linux 7.0.0-28-generic
Architecture: x86-64
Hardware Vendor: QEMU
Hardware Model: Ubuntu 24.04 PC _Q35 + ICH9, 2009_
Hardware Version: pc-q35-noble
Firmware Version: 1.16.3-debian-1.16.3-2
Firmware Date: Tue 2014-04-01
Firmware Age: 12y 3month 2w 4d
kazu@ubuntu2604:~$Checking the Hostname (hostname Command)
hostnamekazu@ubuntu2604:~$ hostname
ubuntu2604
kazu@ubuntu2604:~$The above output is for a host whose hostname is ubuntu2604.
Changing the Hostname (Permanent: hostnamectl Method)
This method keeps the configured hostname even after a system reboot.
sudo hostnamectl set-hostname [NAME]| Field | Value |
|---|---|
| [NAME] | Specify the hostname to set |
kazu@ubuntu2604:~$ sudo hostnamectl set-hostname webserver
kazu@ubuntu2604:~$ hostnamectl
Static hostname: webserver
Icon name: computer-vm
Chassis: vm 🖴
Machine ID: 4a8cf9d0938b433e8fb26a71d7d266a7
Boot ID: b37517594817444bbfa955abceb52cd2
Virtualization: kvm
Operating System: Ubuntu 26.04 LTS
Kernel: Linux 7.0.0-28-generic
Architecture: x86-64
Hardware Vendor: QEMU
Hardware Model: Ubuntu 24.04 PC _Q35 + ICH9, 2009_
Hardware Version: pc-q35-noble
Firmware Version: 1.16.3-debian-1.16.3-2
Firmware Date: Tue 2014-04-01
Firmware Age: 12y 3month 2w 4d
kazu@ubuntu2604:~$The above is an example of changing the hostname to webserver. The prompt doesn’t update immediately — it will reflect the change after you log in again. With this method, the hostname remains changed even after a reboot.
Changing the Hostname (Temporary: hostname Method)
sudo hostname [NAME]| Field | Value |
|---|---|
| [NAME] | Specify the hostname to set |
kazu@ubuntu2604:~$ sudo hostname dbserver
kazu@ubuntu2604:~$ hostname
dbserver
kazu@ubuntu2604:~$The above is an example of temporarily changing the hostname to dbserver. The prompt doesn’t update immediately — it will reflect the change after you log in again. After a reboot, the hostname reverts to what it was before the change.