How to Change Hostname on Ubuntu 20.04

Every computer has a name i.e called Hostname. It is and should unique across the Local Area Network of computers. The Hostname is set when you first install an operating system or you can manually set as per the standard followed by your organization. In this article, we are going to learn how to find and change the hostname on Ubuntu 20.04 LTS.

Finding the Hostname on Ubuntu

First, Let’s find out the current hostname for your Ubuntu desktop. There are many way you can do it. We will cover all below.

Method 1

Login to the Ubuntu terminal and run the hostname command to find out the hostname of your computer as shown below.

$ hostname
imaginelinux

Here you can see the hostname of my computer is imaginelinux.

Method 2

You can also use hostnamectl command to find out the hostname. It gives more information than the hostname command.

hostnamectl
Static hostname: imaginelinux
Icon name: computer-vm
Chassis: vm
Machine ID: fe6e946201814e5f8840d8931a1e7fb4
Boot ID: 1b7cdbf9a3fa43659be0600943f5ad64
Virtualization: oracle
Operating System: Ubuntu 20.04.1 LTS
Kernel: Linux 5.4.0-58-generic
Architecture: x86-64

Static Hostname is the actual host name. You get the Machine id, Operating system name, and other information as well.

Method 3

You can also check the content of the /etc/hosts file using the cat or more command to find out the current host name.

more /etc/host
127.0.0.1 localhost
127.0.1.1 imaginelinux

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Now you know how to find the hostname and let’s see how to change it.

Changing the Hostname on Ubuntu

You have to use hostnamectl command to change host name. This is the how you use it,

sudo hostnamectl set-hostname <new hostname>

Here, Let’s change the hostname from imaginelinux to myubuntu.

sudo hostnamectl set-hostname myubuntu
[sudo] password for imaginelinux:

Now, let’s verify if hostname is changed or not using the command mentioned above.

$ hostname
myubuntu
hostnamectl
Static hostname: myubuntu
Icon name: computer-vm
Chassis: vm
Machine ID: fe6e946201814e5f8840d8931a1e7fb4
Boot ID: 1b7cdbf9a3fa43659be0600943f5ad64
Virtualization: oracle
Operating System: Ubuntu 20.04.1 LTS
Kernel: Linux 5.4.0-58-generic
Architecture: x86-64

You can see the output of the above commands. The hostname is changed to myubuntu.

Note, it does not change the content of /etc/hosts file. You need to manually update it using nano or any other text editor.

Summary

hostnamectl command provides an easy way to change the hostname of the Ubuntu system without rebooting. I hope you found this helpful

Please share and subscribe.

Scroll to Top