How to change the hostname in Ubuntu 18.04

Having the same hostname in Ubuntu for all systems can make maintenance and administrative work on the system, and on the network itself, very difficult to perform.

The hostname (popularly known as hostname) in any Linux-based distribution is used to uniquely identify a system on a network. The default hostname that is set during installation is localhost. For some cloud services, the default hostname is set according to your preferences and is not always localhost.

The installed application uses the hostname as a default identifier while communicating with other systems.

Therefore, in order to communicate with any other system on a network without any confusion, it is always a good idea to change it. In this article, we will see how to change the hostname in Ubuntu LTS 18.04.

Change hostname in Ubuntu using hostnamectl

Remember that in all the methods that we are about to show you, you must use SSH to access your Linux server. Here’s one in case you need a little help.

The easiest way to change the hostname in Ubuntu is by using the hostnamectl command. This command is part of the systemd utilities and is installed by default. If for some reason it is not present on your system, use the following command apt-get to install it:

apt-get install systemd

The hostnamectl command will now be available, if it was not available before. Type hostnamectl at the terminal command line to view system information, including the hostname. This is what the command looks like:

hostnamectl

This is the result you would get after doing so:

See also  What is and how to use WordPress Importer

Static hostname: Icon name: computer-vm Chassis: vm Machine ID: 45598cbdb6ee462e8696166b520fe788 Boot ID: 99526e56aeea45c2a0f3b2ffaaffe9d9 Virtualization: xen Operating System: Ubuntu 18.04.1 LTS Kernel: Linux 4.15.0-1021-aws64 Architecture: x86

The output of the above command reflects the permanent hostname as the static hostname. To change the system’s hostname permanently, simply use the following hostnamectl command:

hostnamectl set-hostname hoster

This command does not produce an output or result. To check the new hostname in Ubuntu, type hostnamectl from the terminal without any options or parameters:

hostnamectl

Change hostname in Ubuntu using hostname command

The hostname command is used to display or set the hostname and domain name of a system. The basic syntax for the command is:

hostname

To see the current configuration of your system, use the hostname without any options or arguments:

hostname

To change the hostname, simply use the hostname command without any options, typing the new hostname as the only argument.

hostname hoster

To check if the hostname has been set correctly, just use the simple hostname command.

Remember that hostname changes in Ubuntu are temporary. If you reboot the system, the hostname will revert to the old one.

The hostname command is useful in a situation where you have a short or small task that requires temporary changes, with which you don’t want to make permanent changes.

Change hostname in Ubuntu manually

It is possible to change the hostname by editing some hostname configuration files directly. You only need to update the hostname in two configuration files: /etc/hostname Y /etc/hosts.

To get started, edit the file /etc/hostname and update the registry with the new hostname:

See also  What is an SMTP port and how to choose the right one

vi /etc/hostname hoster

Next, update the hostname record with the new one in the file /etc/hosts for the system to save the new hostname on the network.

# vi /etc/hosts 127.0.0.1

At this stage you are done with updating records in the configuration files. But you are still one step away from applying the above changes.

In the final step, you need to edit a cloud configuration file. This starter package is installed from the default images provided by some cloud service providers to initialize a cloud instance.

To complete the process, edit the cloud configuration file and change the value of preserve_hostname a true.

# vi /etc/cloud/cloud.cfg


# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: true

If the above file, cloud configuration, He is not present on your system, don’t worry, you can safely skip this step.

Reboot your system and open a terminal session. To verify that the hostname was preserved during the reboot, simply type the following command in the terminal:

hostname

Change hostname in Ubuntu using control panel

To change the hostname using the control panel, simply go to the menu servers, in the top navigation bar, and select the instance for which you want to change the hostname. In the newly opened window, update the value of the hostname to the new one and press Save Changes. Congratulations, you have successfully changed the hostname using the control panel:

conclusion

Changing the hostname in Linux Ubuntu 18.04 is quite easy. You already know how to do it through the control panel and the Linux terminal. Now you can easily manage your network!

See also  Affiliate Program

Gustavo is passionate about creating websites. He focuses on the application of SEO strategies at for Spain and Latin America, as well as the creation of high-level content. When he is not applying new WordPress tricks you can find him playing the guitar, traveling or taking an online course.

Loading Facebook Comments ...
Loading Disqus Comments ...