How to change the Computer name in Ubuntu 20.04 Linux

If you have just installed a new Ubuntu 20.04 Linux on your PC or Laptop and it has used the system’s OS as a computer name, then you can change it. Or you are just a beginner who has set the Linux hostname something, let’s say ‘John’ but after some time you would like to change and reset the computer name to ‘JohnPc’. Then for sure, you might be looking for a way to remove the existing hostname of your Ubuntu 20.04/18.04/19.04/16.04 PC or Laptop. If yes, then this tutorial will help you with that.

What do we learn in this tutorial?

  • How to change the hostname in ubuntu 20.04?
  • How do you find your computer name on ubuntu?

Things we need?

Ubuntu Linux system 20.04,19.04,18.04,17.04,16.04… other open-source Linux OS such as Linux Mint, Elementary OS, Debian are also can be used to follow the below steps. Remember the hostname and Computer name both are the same things.

Note: If you don’t want to use the Command line method and running a graphical user interface then use that: How to change Ubuntu Linux Device name Graphically

Change Ubuntu Linux computer name using the command terminal

1: Open a command terminal.

For the servers skip this step and simply go to the second one. However, those are on GUI, open the command terminal using Show Applications or shortcut keys: Ctrl+Alt+T.

2: Command to check the Ubuntu Linux computer name

First, check the existing Ubuntu hostname of your PC. In case you don’t know it then this will apprise you that. However, the name on command terminal just before the:$ and after the @ is the one you want to change. To get the detail info type: hostnamectl

check the existing Ubuntu hostname of your PC

3: Edit Hostname file

Use VIM or Nano editor to open the /etc/hostname file which contains the computer name of your Linux PC or laptop. The command to edit and update is:

sudo nano /etc/hostname

When the above file will open you will see the existing name of your computer just delete and type the one you want to use.

To save and exit Nano editor: Ctrl+X and type Y followed by the Enter button.

Change the hostname ubuntu 20.04 lts

Step 4: Change the computer name without restart

If you don’t want to restart your Linux computer after changing the hostname, then also follow this extra step to manually update the host file.

Edit host file:

sudo nano /etc/hosts

Now, find theĀ with your existing computer name, once you find it delete and replace it with the one you used in Step 3 of this tutorial.

In the below screenshot you can see that we have h2smedia by replacing the old hostname. Once you are done with all this, save the file.

Change computer name of ubuntu without restarting

Step 5: Check the updated hostname

After changing the computer name, run again the hostnamectl command, this time what you will get is the name you have recently set.

Static hostname: h2smedia
Icon name: computer-vm
Chassis: vm
Machine ID: 5c9584feeb354a1ab4e2f40e393769c9
Boot ID: 212a6e8430184bd0aa31a13e66ed7c8b
Virtualization: oracle
Operating System: Ubuntu 20.04 LTS
Kernel: Linux 5.8.1-050801-generic
Architecture: x86-64

In this way, we can update the computer name not only on Ubuntu but also in other Linux operating systems as well.


Leave a Reply

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