In a Local Area Network (LAN) environment, computer systems need to communicate with each other based on their IP addresses. To learn and remember these IP addresses and sharing them when needed is a tricky business. In order to avoid such trouble, users tend to rename their system’s hostname for their own ease. The simpler hostnames will allow all computer users to coordinate easily without an exchange of large IP addresses. This whole scenario is quite related to the URLs and DNS server address, where the user is totally unaware of long addresses and simply use the URLs in their search engine.

In this tutorial, I will show you two methods to change the hostname of an Ubuntu 20.04 system via the command line terminal and GUI. Users can opt either way to update the names and share them once they have finalized them.


  • Recommended OS: Ubuntu 20.04
  • User account: A user account with sudo rights

How to change the hostname

We will discuss the methods to change the hostname through the command line using hostnamectl command and the GUI of Ubuntu system. The following methods and commands will be run on Ubuntu 20.04 system.

Method # 01

Change the hostname on the shell with the hostnamectl command

To change the hostname permanently, open up the terminal window of the Ubuntu system using the Ctl+Alt+T shortcut or go to ApplicationsTerminal. Once opened, check the current hostname of the device. To display the current hostname, type the hostnamectl command in your terminal.

$ hostnamectl

hostnamectl command

An output containing details of the system like the hostname, and other hardware specifications will appear. In this method, we desire to update the Static hostname field. The pre-existing hostname in our example is ubuntu-VirtualBox.

View hostname

Users can also check the existing hostname by entering the following command in the terminal window:

$ cat /etc/hostname

Get hostname from /etc/hostname file

The existing hostname will be displayed in the output.

Display hostname

To change the currently set hostname, type the following hostnamectl command:

$ sudo hostnamectl set-hostname newNameHere

Set new hostname

You can change the hostname, by replacing it with the newNameHere in the previous command. We are setting the new hostname as ubuntu in the example to get it replaced with the existing name i.e., ubuntu-VirtualBox. In order to make such changes, users need to have sudo rights.

Here the system might ask user for the password. Enter the password in the required field and then press the <enter> key to proceed with the process of changing the hostname

enter password

Once the name is updated, you can verify the updates using:

$ hostnamectl

Run hostname command

The output will appear showing the updated Static hostname.

New hostname has been set

This way you can easily change the hostname via the command line within the Ubuntu system. The changes will be reflected on opening up a new terminal window. Users do not need to restart their computer systems.

Method # 02

Set new Hostname through the GUI

To change the hostname temporarily, open up the Settings of the system. Go to the Settings from the Applications list. Once done, the Settings window will open up.

Network settings

Scroll down to the About section from the left side navbar. The About section is under the Date & Time option as shown in the figure below:

Device name

Here you will see the Device Name field on the right side. The pre-defined name is set as ubuntu-VirtualBox as the hostname. To update it by click on the Device Name field. The Rename Device modal will open up, provide the updated name, and then select the Rename button. In our case, the new hostname is ubuntu.

Rename device

Please note that this is not the permanent hostname. Users can update and rename the hostname based on their choice.

How to verify the updated hostname?

To verify the updated hostname, open up the new terminal window in your computer system. The hostname will be updated as shown in the figure below:

Verify hostname change


In this tutorial, we discussed two methods to change the hostname of the Ubuntu 20.04 system. The first method allows users to update the hostname permanently through the command line and the second method helps them to update the hostname through GUI. Both methods are pretty straight forward and can be followed easily. Users can use either of the method based on their requirements.

How to change the hostname on Ubuntu 20.04 LTS

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn