How to Change Hostname on Ubuntu 25.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: 80189c5e55b84343ad315f8c1632a997
         Boot ID: 244398da562e4a6a8577528d17070237
    Product UUID: 80189c5e-55b8-4343-ad31-5f8c1632a997
  Virtualization: kvm
Operating System: Ubuntu 25.04
          Kernel: Linux 6.14.0-15-generic
    Architecture: x86-64
 Hardware Vendor: Red Hat
  Hardware Model: KVM
Firmware Version: 1.16.0-3.module_el8.7.0+3346+68867adb
   Firmware Date: Tue 2014-04-01
    Firmware Age: 11y 3w 5d

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: 80189c5e55b84343ad315f8c1632a997
         Boot ID: 244398da562e4a6a8577528d17070237
    Product UUID: 80189c5e-55b8-4343-ad31-5f8c1632a997
  Virtualization: kvm
Operating System: Ubuntu 25.04
          Kernel: Linux 6.14.0-15-generic
    Architecture: x86-64
 Hardware Vendor: Red Hat
  Hardware Model: KVM
Firmware Version: 1.16.0-3.module_el8.7.0+3346+68867adb
   Firmware Date: Tue 2014-04-01
    Firmware Age: 11y 3w 5d

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