Skip to main content
  1. Linux Articles/
  2. Ubuntu 26.04 LTS Server/

Changing the Hostname on Ubuntu 26.04 LTS Server

Table of Contents

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)

Command to Check the Hostname
hostnamectl
Example 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:~$

Checking the Hostname (hostname Command)

Command to Check the Hostname
hostname
Example Output of the Hostname Check Command
kazu@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.

Command to Set the Hostname
sudo hostnamectl set-hostname [NAME]
FieldValue
[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.

Changing the Hostname (Temporary: hostname Method)

This method is a temporary change and is not permanent.
Command to Set the Hostname
sudo hostname [NAME]
FieldValue
[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.