How to change the hostname on Ubuntu

Ubuntu 20.04 is a Linux-based operating system that was released on April 23, 2020. It is a better version of Ubuntu 19.10. As every OS of LTS is supported for 5 years thus Ubuntu will also be supported for further 5 years. It was first released on Launchpad and then on Wiki of Ubuntu. It has a fast boot time and many other features. It has different theme variants and a different set of wallpapers that you can apply. This article will provide all the information about how to change the hostname on the latest OS that is Ubuntu. It performs amazing functions and many advantages. Some of them include:

  • Redesigned Login Screen
  • New wallpaper
  • Performance improvements
  • Do not disturb mode
  • Fractional scaling
  • New kernel
  • Amazon app is excluded as the main app

You can change your hostname on Ubuntu by reading the following instructions.

Step 1:

First of all, you have to check your present hostname. To verify it, you need to input hostnamectl or hostname command:

$ hostname

The output of the hostnmectl command could appear to be the same as shown above.

$ hostnamectl

No matter what case the hostname of the operating system will be Ubuntu.

Step 2:

Now you can change your current hostname easily simply by typing the name of your own choice to for example younisx or other hostnames that you want to have by using the following terminal emulator command.

$ sudo hostnamectl set-hostname younisx

The command we just mentioned changes the hostname of our Ubuntu system to younisx. The file below should be edited to change the Ubuntu hostname.


Step 3:

You have to edit the hostname there and then you can easily change your username that is the old one with the new one. Then you have to verify that the new hostname is also present in the file that is given below:

$ cat /etc/hostname

Note: When you change your hostname using the hostnamectl command there is no requirement of system reboot during the process.

Step 4:

After that, we need to edit /etc/hosts file to make changes by typing the command:

$ sudo edit /etc/hosts.

Apply the hostnamectl command so that you can confirm the change in your hostname that will ensure the changes appeared in the system.


You can change your hostname easily by following the above steps one by one. It will help you to log in to Ubuntu with the changed hostname. This will help you have a better experience of Ubuntu and make changes according to your desire. Keep in mind following the exact steps for better and fast results. In the end, you can restart the computer to check if your hostname has changed or not. Have a great experience enjoying the perks of Ubuntu.

About the author

Younis Said

I am a freelancing software project developer, a software engineering graduate and a content writer. I love working with Linux and open-source software.