3 Ways to Change Hostname on Ubuntu 22.04 or 20.04 LTS

If you are using Ubuntu 20.04 LTS Focal Fossa, then here are the commands and GUI method to change the HOSTNAME or Device name.

What is a hostname in Linux?

In plain words, if we have multiple Linux computers in a network then to identify each of them using a custom name, we can generate hostnames, custom names generated by the user. Well, while setting up any OS, the hostname is usually set by it automatically depending upon the system. However, there are many scenarios where we need to set the one manually to easily identify the system over a network so that there will not be any kind of conflict relating to the hostname.

Here we will learn a few easy methods to change the hostname on the popular Ubuntu 20.04 LTS focal fossa server or desktop OS.

Ways to Change Hostname on Ubuntu 20.04 LTS via CLI or GUI

The given steps will also work for Ubuntu 22.04, 21.04, 19.04,18.04; Linux Mint, MX Linux, Rocky and other Linux systems.

Identify existing Hostname

Your system will already have a pre-assigned hostname, let’s first check what is that? The command to print the current hostname on Ubuntu Linux is:





#Ist method:

Change Ubuntu 20.04 hostname for the current session only

If you just want to change the hostname for temporary until your current session is not over or you have not logged out/rebooted your system; use the given command in the terminal.

sudo hostname new-one

Replace the new one with the hostname you want to assign to your system temporarily. To see the changes,  initialize your current environment or rerfersh your current session using:


Command to change hostname ubuntu 20.04


Use hostnamectl set-hostname to change without rebooting (permanent)

Well, if you want to change your hostname permanently without rebooting your Ubuntu Linux, then use the “hostnamectl set-hostname” command.

sudo hostnamectl set-hostname new-one

To see the changes on your terminal, refresh the session:


Change hostname pemanently using set hostname command wihout reboot


#2nd method:

Edit /etc/hostname and /etc/hosts (reboot needed)

Another method to change the name of your computer is by editing two files – /etc/hostname and /etc/hosts.  However, after editing these configuration files the user has to restart the system to apply them. This method is also permanent.

sudo nano /etc/hostname

You will see your existing hostname in the file, just change it to whatever you want to set. To save the file press Ctrl+O, hit the Enter key, and then to exit use Ctrl+X.

Edit /etc/hostname file

In the same way, also edit the host file and change your existing hostname in that as well. This file is used to map the hostnames to the IP address. This configuration is important when the user wants to resolve some ip-address with the hostname.

sudo nano /etc/hosts

command Edit /etc/hostsconfiguration file

After editing and saving the files reboot your system.

sudo reboot


#3rd method:

Use GUI to Change Ubuntu 20.04 Hostname

Well, those who are not comfortable with the command-line method and using graphical desktop can go for the GUI method.

  • Go to Ubuntu 20.04 GUI Setting app.
  • Select the About section given in the left side menu.
  • Click on the Device Name
  • Enter the new hostname you want to use.
  • Click on Rename button to Save the changes

GUI to change ubuntu hostname Rename Device Name Ubuntu



Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.