How to Change the Hostname on Ubuntu 20.04 LTS

1790
Share:
how-to-change-the-hostname-on-ubuntu-20-04-lts

In computer networking, a hostname (archaically nodename) is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication, such as the World Wide Web. Hostnames may be simple names consisting of a single word or phrase, or they may be structured. Each hostname usually has at least one numeric network address associated with it for routing packets for performance and other reasons. 

The hostname is set at the time when the Ubuntu operating system is installed or if you are spinning up a virtual machine it is dynamically assigned to the instance at startup.

In this article, I will show you two methods to change the hostname of an Ubuntu 20.04 system via the command line terminal. The method described in this article will work without the need of restarting your system.

You can change the hostname to anything that you want. However, you shouldn’t use the same hostname on two different computers on a network, as this can cause problems. The hostname is supposed to uniquely identify a computer on a network.

Don’t get too fancy with your hostname.  Host names can only contain letters (a through z), digits (0 through 9), and the hyphen character ( – ), and the period character ( . ). A hostname must begin and end with a letter or number — not a hyphen or period. Letters are also case-insensitive, so “COMPUTER” is equivalent to “computer.” The hostname must be between 2 and 63 characters long, although you’ll probably find shorter hostnames more convenient.

Change hostname using hostnamectl

Systemd based Linux distro such as Ubuntu Linux 20.04 LTS and above can simply use the hostnamectl command to change hostname. To see current setting just type the following command:

$ hostnamectl

An output containing details of the system like the hostname, and other hardware specifications will appear. In this method, we desire to update the Static hostname field. The pre-existing hostname in our example is ubuntu-c3491b.

   Static hostname: ubuntu-c3491b
Icon name: computer-vm
Chassis: vm
Machine ID: 74a9a1ba06e13820cbe5ac583b37c5c2
Boot ID: da436542756a45f3a4491ef18ebd92f0
Virtualization: kvm
Operating System: Ubuntu 20.04.2 LTS
Kernel: Linux 5.4.0-70-generic
Architecture: x86-64

To change hostname from ubuntu-c3491b to jason-server, enter:

$ sudo hostnamectl set-hostname jason-server

Verify the change

To verify that the hostname was successfully changed, once again use the hostnamectl command:

$ hostnamectl
$ hostnamectl
Static hostname: jason-server

Icon name: computer-vm
Chassis: vm
Machine ID: 74a9a1ba06e13820cbe5ac583b37c5c2
Boot ID: da436542756a45f3a4491ef18ebd92f0
Virtualization: kvm
Operating System: Ubuntu 20.04.2 LTS
Kernel: Linux 5.4.0-70-generic
Architecture: x86-64

Final Words

I hope that you now know how to change the hostname on Ubuntu 20.04 LTS. If you run into any issues or have any feedback feel free to drop a comment below.

Tags Linux
Share:

0 comment

Leave a reply

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