Guides and tutorials

Hundreds of tutorials and step by step guides carefully written by our support team.

How to change the hostname of your Linux server

In this manual, we will explain in a simple way the steps that you must follow to change the hostname of your Linux server. Before going into details, however, it is convenient that we review what exactly this is from the hostname.

What is the hostname of a server?

The "hostname" or also known as "computer name" is simply a name that identifies a server (or computer) within a computer network. Essentially hostnames serve a purpose similar to domain names and allow you to identify a machine without the need to memorize IP addresses.

Thus, a machine connected to a private network with IP 192.168.1.30 can be assigned, for example, the name "machine1", while the machine with IP 192.168.1.31 can be assigned the hostname "machine2". In this way, both the administrator and users can interact with both machines without using IP addresses that can be difficult to memorize or could even change.

What is a "Fully Qualified Domain Name"?

Fully Qualified Domain Name or FQDN designates the name of a network accessible from the Internet. An FQDN address can include a hostname to allow a machine to be located from the internet using the DNS system.

For example, suppose we have a computer network called "university":

  • universidad.edu could be an FQDN (assuming the domain is registered), allowing the network to be accessible from the internet.
  • equipo1.universidad.edu would also be a FQDN, allowing the machine "equipo1" to be accessible from the internet.

In general, an FQDN provides a unique address that can be used by any computer on the Internet to communicate with any other.

Change the hostname of a Linux server (Ubuntu)

💡 Attention: This manual follows the steps necessary to change a hostname in Ubuntu 18.04. For other distributions, the necessary steps could be different.

This manual assumes that you have superuser privileges. It may require that you use "sudo" before each command.

1. Change the hostname by editing the file /etc/hostname

nano /etc/hostname

This command will open a text editor that will allow us to edit the name of the server. Once the changes are made, we will only have to save the file and close the editor. It is important to note that the changes are not read immediately by the system so it will be necessary to restart the server or change the hostname explicitly with a command.

2. Change the hostname with a command to avoid having to restart

hostname computername

Using the command "hostname" we can change the name of the computer only for the current session. On the next reboot the server will read again the name written in the file "/etc /hostname". In any case, this command allows us to change the hostname without having to restart the server, so it is appropriate to apply the changes immediately.

3. Set the server FQDN

It can be very desirable to also set the FQDN of the server, allowing it to know its own fully qualified name.

To achieve this, we must edit the file "/etc/hosts": nano /etc/hosts

Next we will create a new entry with the following data: <dirección-ip> <hostname.dominio.extension> <hostname>

For example: 185.32.12.35 machine1.university.edu machine1`

The first term is the IP address, under which the equipment can be located. The second term is the FDQN and the third term is an alias, allowing the “equipo1” itself to locate itself simply under the name "equipo1".

In this way, we will have established the FQDN for the server and it will no longer be necessary for it to use the DNS system to establish a connection with itself.

Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.
Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.