How to Change Hostname in Ubuntu in 2021

Here is a simple command you can use to change the hostname in Ubuntu.

how to

sudo hostnamectl set-hostname new_hostname

Read below to find out what is hostname and another way to change it in Ubuntu-server

What is the hostname in Ubuntu?

By definition, hostname is a name that is assigned to a “host” here host means a computer on a network. So it basically means the name of your computer. This hostname is used for identification of your computer on the network

By default, it is set up when you install Ubuntu or any Linux on your system. The name that you type at the time of installation is used with hardware model number as a hostname. To know what’s the hostname of your system type below command in terminal.

Using hotnamectl command in terminal to change hostname in Ubuntu

Now you can see whats current hostname of your system in terminal in static hostname section.

viewing hostname in terminal

Why change hostname?

See when you were installing Ubuntu you thought naming Tom will be great, but now you are thinking NO Jerry is better. There can be various reasons due to which you might want to change your system’s hostname. But just don’t use the same name for two computers on the same network as it might create problems. Although whatever the reason to change hostname here is a simple method to do so.

How to change in Ubuntu-Linux

It’s quite easy to change the hostname in Ubuntu Linux. Just open Terminal either by searching or by pressing Ctrl + Alt + T keys together. Type below commands and you are done.

hostnamectl set-hostname new_hostname

Here replace new_hostname with whatever you would like to keep. You can verify by entering hostnamectl command in terminal.

But this method doesn’t seem to work on Ubuntu-Server so if you are using Ubuntu-server follow the method below.

How to change in Ubuntu-Server

Type the following commands in terminal:

sudo hostname new_server_name

Next, edit the /ect/hostname file and update hostname:

sudo nano /etc/hostname

Finally, edit the /etc/hosts file and update the lines that read your old-host-name:

sudo nano /etc/hosts

From: Old_hostname to new_hostname

Save and close the file and its done.

If you are facing any problems please do let us know in comments. Any other problem you are facing on your computer and want to fix it do let us know in comments we would try to help you as much as we can.

Do you want to know how to screenshot on Snapchat without them knowing? here is how you can do it.

Leave a Reply

Share via
Copy link
Powered by Social Snap