ana bilgisayar adı

How to Change Hostname on Ubuntu 20.04

How to Change Hostname on Ubuntu 20.04
You might have just installed Ubuntu, or you just want to change your hostname due to any reason, then you are exactly at the right place, and this post will guide you on how to change the hostname on Ubuntu 20.04 without restarting your machine. But before getting started, let's understand the hostname first.

What is Hostname?

The hostname indicates the device name over the network. Since it identifies the device name on the network, so it is not a better practice to have the same name over the same network. Normally, it is set during the Operating system's installation process, but we can also change it to avoid name duplication.

In Ubuntu 20.04, the hostnames are stored in the “/etc/hostname” file, and only the root user or the user having the sudo privileges can alter these hostnames. So let's start with the very first command for showing the current hostname in the terminal.

Show Present Hostname

The present hostname can be printed out on the terminal by typing the terminal's following simple command.

$ hostnamectl

You can see in the screenshot above that the hostname of my Ubuntu system is ubuntuBox. Now let's see how to change it.

Change the Hostname

We can change the hostname on Ubuntu 20.04 LTS system using two different methods.

Method 1:

The hostname can easily be changed by providing the new hostname to the hostnamectl command with sudo privileges by using the following syntax.

$ sudo hostnamectl set-hostname ubuntuHost

After running the command for changing the hostname, you can verify the new hostname by again typing the “hostnamectl” command.

$ hostnamectl

You can witness in the screenshot that the hostname is updated successfully.

Method 2:

We can also change the hostname on Ubuntu by editing the “/etc/hostname” file by opening it in any text editor like nano. To open the “/etc/hostname” file in the nano editor, type the command given below.

$ sudo nano /etc/hostname

And now replace the old hostname with the new hostname of your choice.

After changing the hostname, save the file and exit using the shortcut keys(CTRL+S) and (CTRL+X).

Now again, run the command “hostnamectl” to verify the newly assigned hostname.

$ hostnamectl

You can see the newly provided hostname is changed successfully on Ubuntu 20.04.

If you close and reopen the terminal or open a new tab in the terminal, you can also see the changed hostname highlighted in the attached screenshot.

You have successfully changed the hostname, but you need to edit the “/etc/hosts” file and provide the new hostname there as well because the hostnames are mapped in this file.

Change the mapped hostname

$ sudo nano /etc/hosts

Replace the old hostname with the new one you have just set for the device in the “/etc/hostname” file.

Once it is altered as well, Save it and exit from the nano text editor using the shortcut keys (CTRL+S) and (CTRL+X).

Now, you have successfully changed your hostname.

Conclusion

This article shows how to change the Ubuntu 20.04 LTS system's hostname without even restarting your system.

Linux için En İyi 5 Arcade Oyunu
Günümüzde bilgisayarlar oyun oynamak için kullanılan ciddi makinelerdir. Yeni yüksek puanı alamazsan, ne demek istediğimi anlayacaksın. Bu yazıda, bug...
Wesnoth 1 Savaşı.13.6 Geliştirme Yayınlandı
Wesnoth 1 Savaşı.13.Geçen ay yayınlanan 6. sürüm, 1. sürümdeki altıncı geliştirme sürümüdür.13.x serisi ve özellikle kullanıcı arayüzü için bir dizi i...
Ubuntu 14'te League Of Legends Nasıl Kurulur.04
League of Legends hayranıysanız, bu, League of Legends koşusunu test etmeniz için bir fırsattır. Linux kullanıcısıysanız LOL'nin PlayOnLinux'ta destek...