How to Change Hostname on Ubuntu 23.10

Displaying the Current Hostname

To find out your current system name by running the following command.

hostnamectl

Output:

      root@vps:~# hostnamectl
 Static hostname: localhost
       Icon name: computer-vm
         Chassis: vm 🖴
      Machine ID: dbc2524c77264187abe3dbad86c14bc5
         Boot ID: e288824410b94cecab7ff48333193b5d
  Virtualization: kvm
Operating System: Ubuntu Noble Numbat (development branch)
          Kernel: Linux 6.8.0-11-generic
    Architecture: x86-64
 Hardware Vendor: Red Hat
  Hardware Model: KVM
Firmware Version: 1.16.0-4.module_el8.9.0+3659+9c8643f3
   Firmware Date: Tue 2014-04-01
    Firmware Age: 9y 11month 2w   
      root@vps:~#

Changing the System Hostname

Now that you know the current hostname, you can change the hostname by using the following command and set the hostname as follows.

hostnamectl set-hostname vps.crowncloud.net

Replace "vps.crowncloud.net" with your preferred hostname.

Also, it is necessary to update the hostname in the /etc/hosts file to successfully change the name of the Ubuntu server.

nano /etc/hosts

Replace the old hostname with the new hostname, then save the file and exit.

  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'll also have to modify the cloud.cfg file. To edit the cloud.cfg file, by using the following command.

nano /etc/cloud/cloud.cfg

Find preserve_hostname: false and change it to preserve_hostname: true.

preserve_hostname: true

Save the file and exit,

Verify the change

To verify the hostname has been fully changed, enter the hostnamectl command:

hostnamectl

Output:

      root@vps:~# hostnamectl
 Static hostname: vps.crowncloud.net
       Icon name: computer-vm
         Chassis: vm 🖴
      Machine ID: dbc2524c77264187abe3dbad86c14bc5
         Boot ID: e288824410b94cecab7ff48333193b5d
  Virtualization: kvm
Operating System: Ubuntu Noble Numbat (development branch)
          Kernel: Linux 6.8.0-11-generic
    Architecture: x86-64
 Hardware Vendor: Red Hat
  Hardware Model: KVM
Firmware Version: 1.16.0-4.module_el8.9.0+3659+9c8643f3
   Firmware Date: Tue 2014-04-01
    Firmware Age: 9y 11month 2w