How to Check the Hostname
Using hostnamectl
Command to Check the Hostname
hostnamectlExample Output of the Hostname Check Command
kazu@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:~$Using hostname
Command to Check the Hostname
hostnameExample Output of the Hostname Check Command
kazu@ubuntu2604:~$ hostname
ubuntu2604
kazu@ubuntu2604:~$The above output is for a host whose hostname is ubuntu2604.
How to Change the Hostname
Permanent Change: the hostnamectl Method
A command that keeps the configured hostname even after a system reboot.
Command to Set the Hostname
sudo hostnamectl set-hostname [NAME]| Field | Value |
|---|---|
| [NAME] | Specify the hostname to set |
Example of Running the Hostname Set Command
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.
Temporary Change: the hostname Method
This method is a temporary change and is not permanent.
Command to Set the Hostname
sudo hostname [NAME]| Field | Value |
|---|---|
| [NAME] | Specify the hostname to set |
Example of Running the Hostname Set Command
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.