×


Change Host Name on Ubuntu 20.04 - How to perform this task ?

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.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Ubuntu related queries.

In this context, we shall look into methods to change your hostname on Ubuntu 20.04.


How to change Hostname on Ubuntu 20.04 ?

To change the Hostname on a Ubuntu 20.04 system, you can apply the different methods below.


Method 1. The GUI based Method for Changing the Hostname on Ubuntu 20.04

You can follow the steps given below to change the Hostname of your Ubuntu 20.04 system using the GUI based method.

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.


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.


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.


4. Verify your Changed Hostname on Ubuntu 20.04:

Finally, you can verify the changed hostname by looking at the Device Name entry now.


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.

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

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.


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.


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:

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.

You can replace that hostname with any new hostname and then you can save this file.


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. You can locate the hostname that you wish to change.

Now, type in a new hostname after which you can save this file.


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


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.


[Need urgent assistance in configuring the hostname on any Linux Distributions? We are here to help you today. ]


Conclusion

This article covers both the CLI and GUI based methods of changing the hostname on Ubuntu 20.04. 

To change the hostname on Ubuntu Linux:

1. Type the following command to edit /etc/hostname using nano or vi text editor: $ sudo nano /etc/hostname. Delete the old name and setup new name.

2. Next Edit the /etc/hosts file: sudo nano /etc/hosts.

3. Reboot the system to changes take effect: sudo reboot.


To change the hostname on Ubuntu:

1. To change the hostname invoke the hostnamectl command with the set-hostname argument followed by the new hostname. 

2. Only the root or a user with sudo privileges can change the system hostname. 

3. The hostnamectl command does not produce output.


To change the localhost hostname (static name in the hostname file)?

1. You can also set the static hostname manually by editing /etc/hostname

2. This file contains exactly one line by default. 

3. If you have not changed the hostname yet, then that line probably reads localhost. localdomain .


To display the current Ubuntu hostname:

Simply type the following command:

$ hostnamectl


To change Ubuntu LTS hostname permanently:

1. Type the hostnamectl command :

$ sudo hostnamectl set-hostname newNameHere

2. Delete the old name and setup new name.

3. Next Edit the /etc/hosts file:

$ sudo nano /etc/hosts

Replace any occurrence of the existing computer name with your new one.

4. Reboot the system to changes take effect:

$ sudo reboot


To change hostname on Ubuntu without a system restart:

1. Let us see current setting just type the following command:

$ hostnamectl

2. Next change hostname from localhost to linuxapt, enter:

$ hostnamectl set-hostname linuxapt

3. Verify new changes:

$ hostnamectl