A hostname is a unique label that identifies a machine on the network. You shouldn’t have two machines using the same hostname on a given network. If you decide that the name chosen at installation time or assigned automatically is not what you want, you can follow the steps below to update to a new name. Although this tutorial is written for Ubuntu Linux, it should also apply to other Linux Debian-based systems. Also, for students and new users learning Linux, the easiest place to start learning is Ubuntu Linux. Ubuntu is the modern, open-source Linux operating system for desktops, servers, and other devices. When you’re ready to change or rename Ubuntu Linux, follow the steps below.

How to display the current hostname on Ubuntu Linux

Before changing or updating the hostname on Ubuntu, you may want to know what the current name is. You can find out the hostname on Ubuntu by running the commands below. That should display something similar to the lines below with a hostname for your Ubuntu computer.

How to rename the hostname on Ubuntu Linux

Now that you know the hostname for your Ubuntu machine, you can change or rename the machine with a simple command. There are multiple files that you may have to edit to change the hostname on Ubuntu Linux. To quickly change the hostname on Ubuntu, run the commands below using the hostnamectl command. For example, to change the hostname to vm1.ubuntuos.local, run the commands below. Two files should also be edited to successfully change the Ubuntu computer name. These files are located in the /etc directory. They are: Edit /etc/hosts and update the file name there. Then replace the old name with the new one, then save the file, and exit. Then verify that the new hostname is also in the file below: Some cloud providers will install the cloud-init package. Ubuntu servers might also install it. If it is installed you will also need to edit the cloud.cfg file. If there’s a such file on your system, then open it and change the lighted line to preserve the hostname. If you manually installed Ubuntu Linux, then you may not see the cloud.cfg file. In that case, skip the steps below. On cloud host Ubuntu computer with the cloud.cfg configuration file, run the commands below to open the file. Then change the highlighted line to true. The preserve_hostname in the /etc/cloud/cloud.cfg context should be set to true. When it is set to false, it doesn’t preserve hostname changes across a reboot. Set to true or yes, and it preserves the new hostname when you reboot. Save the file and exit Finally, restart the server for the new name to apply. When you log back in, the system should have a new name you assigned. Conclusion: This post showed you how to change the hostname on Ubuntu Linux. If you find any error above or have something to add, please use the comment form below.