Introduction:
A system hostname is an entity that is used to uniquely identify a system within a network. It is also known as the device name of a system. This name is usually assigned to your system when you install an operating system on it. However, at times, you may feel like changing that previously set host name or device name for any reason. Therefore, today we will be learning all the different methods of changing your hostname on Ubuntu 20.04.
Methods of Changing the Hostname on Ubuntu 20.04:
For changing the Hostname on a Ubuntu 20.04 system, you can pick any method of your choice from the ones discussed below:
Method # 1: The GUI based Method for Changing the Hostname on Ubuntu 20.04:
To change the Hostname of your Ubuntu 20.04 system using the GUI based method, you will have to perform the following steps:
Step # 1: Access your Ubuntu 20.04 System’s Settings:
First, you have to search for Settings in your Activities search menu and then click on the Settings search result as highlighted in the image shown below:
Step # 2: Switch to the About Tab in the Settings Window and Click on the Current Device Name:
In the Settings window, you need to switch to the “About” tab. Here, you will be able to see an entry titled Device Name which in fact, refers to your hostname. You need to click on this entry to change it as highlighted in the following image:
Step # 3: Change your Hostname on Ubuntu 20.04:
When you will click on the Device Name entry, a dialogue box will appear on your screen. In this dialogue box, you can type in a new hostname in the space provided and then click on the Rename button as highlighted in the image shown below:
Step # 4: Verify your Changed Hostname on Ubuntu 20.04:
Finally, you can verify the changed hostname by looking at the Device Name entry now as highlighted in the following image:
Method # 2: The “hostnamectl” Command Method for Changing the Hostname on Ubuntu 20.04:
To change the Hostname of your Ubuntu 20.04 system using the “hostnamectl” command method, you will have to perform the following steps:
Step # 1: Check the Current Hostname of your Ubuntu 20.04 System:
First, you need to check the current hostname of your Ubuntu 20.04 system with the command shown below:
hostnamectl
The current hostname of our system is highlighted in the following image:
Step # 2: Change the Hostname of your Ubuntu 20.04 System using the “hostnamectl” Command:
Now, we can change this hostname by executing the command shown below:
hostnamectl set-hostname new-hostname
Instead of new-hostname, you can type any new hostname of your choice as shown in the following image:
Step # 3: Verify your Changed Hostname on Ubuntu 20.04:
You can confirm if the hostname has been changed or not by executing the “hostnamectl” command once again. From the output of this command, you can verify that the hostname of your Ubuntu 20.04 system has been changed as shown in the image below:
Method # 3: The File based Method for Changing the Hostname on Ubuntu 20.04:
To change the Hostname of your Ubuntu 20.04 system using the file-based method, you will have to perform the following steps:
Step # 1: Change the Hostname in the “/etc/hostname” File on Ubuntu 20.04:
First, we need to access the /etc/hostname file with the following command:
sudo nano /etc/hostname
This file will contain your current hostname as shown in the image below:
You can replace that hostname with any new hostname as shown in the following image and then you can save this file.
Step # 2: Change the Hostname in the “/etc/hosts” File on Ubuntu 20.04:
Now, we need to access the /etc/hosts file with the command shown below:
sudo nano /etc/hosts
This file contains the IP addresses corresponding to hostnames as shown in the following image. You can locate the hostname that you wish to change.
Now, type in a new hostname at the located spot as highlighted in the image shown below after which you can save this file.
Step # 3: Reboot your Ubuntu 20.04 System:
For the changes that you have just made to take effect, you have to reboot your Ubuntu 20.04 system with the following command:
sudo systemctl reboot
Step # 4: Verify your Changed Hostname on Ubuntu 20.04:
Once your system is rebooted, you can verify your changed hostname by executing the “hostnamectl” command yet again. The output of this command will reveal that your hostname has been changed successfully as shown in the image below:
Conclusion:
In this article, we shared with you both the CLI and GUI based methods of changing the hostname on Ubuntu 20.04. You can pick any method out of these as per your preferences. However, an important point to be noted over here is that the hostname or device name does not refer to your user account name and it will remain unchanged no matter which of these methods you choose to follow.