Ubuntu

How to Change Hostname on Ubuntu 20.04?

Introduction

The open-source operating system Ubuntu is a famous choice when it comes to managing a computer. Common tasks associated with Ubuntu include hardware control, file management, task scheduling, security management, etc. Every computer system using Ubuntu and any other operating system has a unique name chosen by the user, just like how every person has a special name that helps in identifying them.

This article is going to focus on that special name, which is known as “hostname” in Ubuntu. We will guide you to change hostname on ubuntu 20.04 through this easy-to-understand piece. Let’s kickstart this article with an important process to check the current hostname.

Check Current Hostname on Ubuntu 20.04

The “hostname” command is the option that will display the current name. The user will have to open the terminal by pressing Ctrl+Alt+T. There is another method to open the terminal, which is by directly searching for it on the application menu. Let’s see how the command will work in the terminal.

Check Current Hostname on Ubuntu 20.04

The current hostname will be on display when the user presses the “enter” key.

How to Temporarily Change Hostname on Ubuntu 20.04?

A user can opt to change the name of the system. The common thought process behind doing so is to enhance security, aid in software testing, and more. The user can easily act by using the following command.

How to Temporarily Change Hostname on Ubuntu 20.04

Once the user replaces the “new-hostname” with the latest name, the system will have the changed name until it is rebooted. The original system name will remain unchanged.

Change Hostname on Ubuntu 20.04 without System Reboot

First of all, we will open the terminal by pressing Ctrl+Alt+T. Once the terminal window is open, we will enter the “hostname” command in the terminal to view the current name of the system. After the current name is on display, the user will have to use the “hostnamectl” to change hostname ubuntu 20.04. 

Change Hostname on Ubuntu 20.04 without System Reboot

In the above command, the user will have to replace “new-hostname” with the chosen name and press the enter key. The user can confirm the modification in the name through the “hostnamectl” command, which will eventually display the output in the following manner. 

Change Hostname on Ubuntu 20.04 without System Reboot

In the above command, the static hostname is more of a technical part of identification on the server. On the other hand, “Web Server 1” is more human-readable than the static one.

  • Change the “Pretty” Hostname

A pretty hostname that is easier to understand by humans can be changed through the following command.

Change Hostname on Ubuntu 20.04 without System Reboot

In the above command, the user has changed the static hostname – web-server is changed to pretty hostname – Jaya’s server 1.

Also Read: What is the Linux Date Command?

Change Hostname on Ubuntu 20.04 – Alternative Method (Reboot Required)

The user is free to change hostname Ubuntu 20.04 through other commands as well that require a reboot. The below command is the best way to get the hostname Ubuntu changed permanently.

Change Hostname on Ubuntu 20.04 – Alternative Method (Reboot Required)

In the above syntax, the user has used a text editor called “nano” (another alternative is “vi”). The term “/etc/hostname” is a file that contains the current static hostname of the system. Once you enter the above syntax, the terminal window will display the current hostname, which the user can easily replace with a new one.

The next step is to edit the “etc/hosts” file, which is used to connect the hostname to an IP address. This process of connection is essential to make things easier in terms of hostname on the server for easy access by the user. The file can be edited through the below command.

Change Hostname on Ubuntu 20.04 – Alternative Method (Reboot Required)

When the user presses the enter key after using the above command, something like this will appear on the screen. 

Change Hostname on Ubuntu 20.04 – Alternative Method (Reboot Required)

The user now needs to replace the “old-hostname” with the chosen one. Suppose the user has chosen the name “Victoria server,” then the output will be as follows. Simply press the keys Ctrl+O at last to save the file. 

Change Hostname on Ubuntu 20.04 – Alternative Method (Reboot Required)

The last and final step includes a reboot, which is done after modifications in both files. The user needs to run the below command to complete the process. When the user presses the enter key, all the changes will be applied effectively.

Change Hostname on Ubuntu 20.04 – Alternative Method (Reboot Required)

Change Hostname on Ubuntu 20.04 Using GUI

The GUI option is one of the easiest options to change hostname on Ubuntu 20.04. The user needs to right-click on the blank space on the Ubuntu desktop, and it will lead to the settings menu. Once the user clicks on the settings menu, a window will open on the screen. The user needs to find out the “about” option, which is usually present at the end of the list. When the user clicks on the “about” option, detailed information will appear on the screen regarding the device. In that information, the user will have to change the hostname under the rename section by clicking on the device name box. That’s it; the process is complete.

Also Read: Installing Samba on Ubuntu: Step-by-Step Guide

Conclusion

This article is entirely based on the process to change hostname Ubuntu 20.04. The very first headline is associated with checking the hostname through the “hostname” command in the terminal. This was followed by the process of temporarily changing the hostname on Ubuntu 20.04. Furthermore, we have provided the reader with two options for changing the hostname: one that requires a reboot and one that does not. The last section of this piece talks about the Ubuntu server’s change in hostname permanently through the GUI method. 

Arpit Saini

He is the Chief Technology Officer at Hostbillo Hosting Solution and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *