How to Change Hostname on Ubuntu 18.04 Bionic Beaver

Change Hostname on Ubuntu

In this article, we will have explained the necessary steps to change Hostname on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

A hostname is a name assigned to a “host” i.e. a computer on a network. The hostname is basically just your computer’s name. It’s used to identify your computer on the network.

Change Hostname on Ubuntu

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

Step 2. Change hostname in Ubuntu Using Command Line.

Open a terminal and use the command below to change the hostname. Replace <new_hostname> with the new hostname you want to use:

To change your hostname permanently, you’ll also need to edit your /etc/hostname and /etc/hosts file, which is where Ubuntu distributions store the hostname:

If the cloud-init package is installed you also need to edit the cloud.cfg file. This package is usually installed by default in the images provided by the cloud providers such as AWS and it is used to handle the initialization of the cloud instances:

Search for preserve_hostname and change the value from false to true:

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

That’s all you need to do to change Hostname on Ubuntu 18.04. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.