How to Change Hostname on Ubuntu 24.10
Displaying the Current Hostname
To find out your current system name by running the following command.
hostnamectl
Output:
root@server:~# hostnamectl
Static hostname: server
Icon name: computer-vm
Chassis: vm 🖴
Machine ID: 7e3c835b73b44f50a7e676144e993199
Boot ID: e1342d5b583e457683444259eee32b05
Product UUID: ab5e548c-fe08-4f6f-82c8-cd8ac4b87875
Virtualization: kvm
Operating System: Ubuntu 24.10
Kernel: Linux 6.11.0-9-generic
Architecture: x86-64
Hardware Vendor: Red Hat
Hardware Model: KVM
Firmware Version: 1.16.0-4.module_el8.8.0+3612+f18d2b89
Firmware Date: Tue 2014-04-01
Firmware Age: 10y 7month 1d
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@server:~# hostnamectl
Static hostname: vps.crowncloud.net
Icon name: computer-vm
Chassis: vm 🖴
Machine ID: 7e3c835b73b44f50a7e676144e993199
Boot ID: e1342d5b583e457683444259eee32b05
Product UUID: ab5e548c-fe08-4f6f-82c8-cd8ac4b87875
Virtualization: kvm
Operating System: Ubuntu 24.10
Kernel: Linux 6.11.0-9-generic
Architecture: x86-64
Hardware Vendor: Red Hat
Hardware Model: KVM
Firmware Version: 1.16.0-4.module_el8.8.0+3612+f18d2b89
Firmware Date: Tue 2014-04-01
Firmware Age: 10y 7month 1d
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