Change Hostname on Ubuntu with GUI and CommandLine

22

In a computer, a networking hostname is a label assigned to a device and used as identification of a specific device over a network. The hostname is a name of a device that is set during the installation of the operating system.

The hostname of a device can be changed anytime, no matter what desktop environment you are using.

This post is focusing on various methods to change the hostname of your device specifically for Ubuntu users.

How to Change Hostname on Ubuntu 20.04 (LTS) and 20.10?

The hostname can be renamed in two different ways, either via GUI or through the terminal:

1. Changing Hostname through GUI:
On Ubuntu desktop, right-click to get the Settings menu:

After this, the “Settings” window will appear with numerous options. Find the “About” option, click on that to see the relevant settings:

Change Hostname on Ubuntu with GUI and CommandLine 1617262592 500 Change Hostname on Ubuntu with GUI and CommandLine

Clicking on the “Device Name”, as shown in the above image, a dialogue box will appear and ask you to rename the hostname.

Change the current hostname according to your choice and hit on Rename button to save the new hostname.

Change Hostname on Ubuntu with GUI and CommandLine 1617262592 206 Change Hostname on Ubuntu with GUI and CommandLine

2. Change Hostname Through Terminal:

Check Current Hostname

To change hostname using the command line, first, we need to check its current name, which can be found using any of two commands:

Change Hostname on Ubuntu with GUI and CommandLine 1617262593 708 Change Hostname on Ubuntu with GUI and CommandLine

Another choice is using the following command that will show you the detailed status of your system:

Change Hostname on Ubuntu with GUI and CommandLine 1617262593 710 Change Hostname on Ubuntu with GUI and CommandLine

Change Hostname

The syntax of the command to change hostname is:

$ hostnamectl set-hostname [new-hostname]

Replace the new-hostname with your desired name. You won’t get any output or notification on the terminal, but it will be changed in the backend.

For example:

$ hostnamectl set-hostname linuxhint

Change Hostname on Ubuntu with GUI and CommandLine 1617262594 583 Change Hostname on Ubuntu with GUI and CommandLine

To verify it, type “hostnamectl” to get the output:

Change Hostname on Ubuntu with GUI and CommandLine 1617262595 420 Change Hostname on Ubuntu with GUI and CommandLine

Pretty Hostname

Many people wish to set the pretty hostname for their devices, to do so, follow the below-given process.

First, let’s check the syntax of the pretty hostname command:

$ hostnamectl set-hostname “new-hostname” –pretty

Now, replace “new-hostname” with your own choice. I will use “Linuxhint Desktop”. So, the command will be like this:

$ hostnamectl set-hostname “Linuxhint Desktop” –pretty

Change Hostname on Ubuntu with GUI and CommandLine 1617262595 353 Change Hostname on Ubuntu with GUI and CommandLine

Conclusion:

The hostname is an identity of a device over a network and can be modified anytime. We have gone through a detailed guide on how to change the hostname on Ubuntu and learned two easy approaches. The hostname can be changed through GUI or command-line. So, pick the technique you want and follow the steps.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More