Ubuntu 22.04 was launched on April 21, 2022. The final release of Ubuntu 22.04 is available and that means everyone can start using it even on production servers. Ubuntu 22.04 has many improvements including faster boot times and bug fixes.
Just like with a brand new computer, setting an Ubuntu 22.04 hostname is a pivotal process. This might sound tricky when it comes to provisioning your VPS server for the first time. Some people might not care about the Linux’s hostname during the initial process. However, this can lead to a lot of confusion if an administrator is logging to different VPS instances.
A hostname should give quick relevant information about the system where one is logged in. This doesn’t come out of the box and most data centres and hosting company will really set some weird hostnames on new Ubuntu 22.04 instances.
A hostname is simply a label that is assigned to a device on a network to distinguish it from the rest of the devices. Or you might refer to the hostname as another name for “Computer Name“. Hostnames play an important role when it comes to resolving common easy to remember names to IP addresses through the DNS service.
You may use any hostname for your Ubuntu 22.04 server but most people name it after planets or even animals and others will pre-fix the location of the server on the name .e.g New_York_Pluto, Miami_proxima_b.
In this guide, I will show you how to change the name of your Ubuntu 22.04 server.
Prerequisites
- An VPS server running Ubuntu 22.04
- A non-root user with sudo privileges
Step 1: Checking the default hostname
First, login to your terminal window and type the command below to get your current hostname.
$ hostname
or
$ hostnamectl
The command hostname will display your Ubuntu 22.04’s current hostname. If you use the second alternative hostnamectl, you will see a lot of information about your server as shown in the image below
Step 2: Changing the hostname
In Ubuntu 22.04, you will be required to edit two files to change your hostname. To edit the first file, type the command below on a terminal window:
$ sudo nano /etc/hostname
Editing the /etc/hostname
As seen above, the hostname will be displayed at the top of the file. You need to overwrite that value with your desired hostname. Then, press CTR+O to save changes and Ctrl+X to exit from this window.
Changing Ubuntu 22.04 server name on the hosts file
You will also need to edit the /etc/hosts file. To do this, type the command below on a terminal window:
$ sudo nano /etc/hosts
As seen above. The first line on the hosts file displays the localhost on the IP address 127.0.0.1. Leave that line intact. Then you will need to edit/add the hostname on the second line after the loop back IP address 127.0.1.1. Also, you might find it necessary to reference your VPS hostname under your Ubuntu 22.04 server’s public IP address by adding a third line as show below.
127.0.0.1 localhost 127.0.1.1 Ubuntu-VirtualBox x.x.x.x variety_village
Step 3: Reboot the system
In order for the changes to take place, you need to restart your Ubuntu 22.04 server. Type the command below
$ sudo reboot
Conclusion
That’s it; you have changed your Ubuntu 22.04 hostname. Remember you can always check if your hostname was changed successfully by typing the command ‘hostname’ one more time on the terminal window. If everything went as expected, you will be able to login on your Ubuntu VPS instance without any confusion.