How to Change Hostname on Ubuntu 26.04
Displaying the Current Hostname
To find out your current system name, run the following command:
hostnamectl
Output:
root@server:~# hostnamectl
Static hostname: server
Icon name: computer-vm
Chassis: vm 🖴
Machine ID: 4ba47688027d4ab2a45704ea84959b93
Boot ID: d65ce7b470db47e5949eeefd55606d33
Product UUID: 4ba47688-027d-4ab2-a457-04ea84959b93
Virtualization: kvm
Operating System: Ubuntu 26.04 LTS
Kernel: Linux 7.0.0-14-generic
Architecture: x86-64
Hardware Vendor: Red Hat
Hardware Model: KVM
Hardware Version: RHEL 7.6.0 PC _i440FX + PIIX, 1996_
Firmware Version: 1.16.0-4.module_el8.9.0+3659+9c8643f3
Firmware Date: Tue 2014-04-01
Firmware Age: 12y 3w 3d
Changing the System Hostname
Now that you know the current hostname, change it by running:
hostnamectl set-hostname vps.crowncloud.net
Replace vps.crowncloud.net with your preferred hostname.
It is also necessary to update the hostname in the /etc/hosts file:
nano /etc/hosts
Modify it like this:
127.0.0.1 localhost
127.0.1.1 vps.crowncloud.net
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
If cloud-init is installed on your Ubuntu server, you also need to modify the cloud.cfg file:
nano /etc/cloud/cloud.cfg
Find the line:
preserve_hostname: false
Change it to:
preserve_hostname: true
Save the file and exit.
Verifying the Change
To verify that the hostname has been fully changed, run:
hostnamectl
Output:
root@server:~# hostnamectl
Static hostname: vps.crowncloud.net
Icon name: computer-vm
Chassis: vm 🖴
Machine ID: 4ba47688027d4ab2a45704ea84959b93
Boot ID: d65ce7b470db47e5949eeefd55606d33
Product UUID: 4ba47688-027d-4ab2-a457-04ea84959b93
Virtualization: kvm
Operating System: Ubuntu 26.04 LTS
Kernel: Linux 7.0.0-14-generic
Architecture: x86-64
Hardware Vendor: Red Hat
Hardware Model: KVM
Hardware Version: RHEL 7.6.0 PC _i440FX + PIIX, 1996_
Firmware Version: 1.16.0-4.module_el8.9.0+3659+9c8643f3
Firmware Date: Tue 2014-04-01
Firmware Age: 12y 3w 3d CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS