How to change Hostname on Ubuntu 18.04/20.04
28 August 2020 | Category : Ubuntu
A hostname is a unique name computer in a network for identity between one computer to another computer. Each computer/server is connected on the network must have a different name for hostname and the hostname must be FQDN (Fully Qualified Domain Name).
At this time we will share with you about How to change hostname on Ubuntu 18.04/20.04. To changing the hostname we will show in two ways, the first you will change the hostname from the command line and the second is from edit the file configuration.
Change Hostname on Ubuntu 18.04/20.04
Show the current Hostname
Before changing hostname you need to know your current hostname. To view the current hostname you can run this command :
And the above command will show outike this :
hostnamectl Static hostname: shukuma Icon name: computer-vm Chassis: vm Machine ID: 7830927c3bc24254a018fea5372f9294 Boot ID: fcb05de2afa742ca9b527612ab56f1c1 Virtualization: kvm Operating System: Ubuntu 18.04.5 LTS Kernel: Linux 4.15.0-115-generic Architecture: x86-64
The above output in section Static hostname it showing the current hostname is set to shukuma
Change the hostname
Change hostname with command line
As we said before, to change the hostname in this article will be shown in two ways. Firstly, we will explain the change hostname with the command line.
To change it with the command you can follow this command line below :
hostnamectl set-hostname your.hostname.domain
Example you can run the above command like this :
hostnamectl set-hostname shukuma.linux-id.net
And to verify the hostname has been changed or not you can run the command
And the output of the above command will show like this :
hostnamectl status Static hostname: shukuma.linux-id.net Icon name: computer-vm Chassis: vm Machine ID: 7830927c3bc24254a018fea5372f9294 Boot ID: fcb05de2afa742ca9b527612ab56f1c1 Virtualization: kvm Operating System: Ubuntu 18.04.5 LTS Kernel: Linux 4.15.0-115-generic Architecture: x86-64
Change hostname with edit file configuration
The next way to changing the hostname is with edit file configuration on /etc/hosts. This file /etc/hosts is the configuration file to edit the hostname, you can also set the hostname from this file.
To edit the file /etc/hosts you can use this command :
And then on the file /etc/hosts, you can add this line
127.0.0.1 shukuma.linux-id.net shukuma
Before or after this line
So, the configuration it will like this :
127.0.0.1 shukuma.linux-id.net shukuma 127.0.0.1 localhost # 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 ff02::3 ip6-allhosts
And to implement this configuration you must reboot the server or computer first. After rebooting you can verify the configuration with command this :
And the output above command will show like this :
hostname -A shukuma.linux-id.net shukuma
Every computer or server is connected to the network it’s will have a unique hostname and this hostname will be different from each computer or server. To change the hostname you can choose one of two ways above, if you want to change the hostname without restart the computer or server you can be changing the hostname from command line hostnamectl.