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 to follow to change the hostname of your Linux server. Before going into details, it is convenient to review what exactly is a hostname.

What is the hostname of a server?

The "hostname" or also known as a "computer name" is simply a name that identifies a server (or computer) within a computer network. Essentially, hostnames serve a similar purpose to domain names and allow a machine to be identified 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 a machine with IP 192.168.1.31 can be assigned the hostname "machine2". In this way, both the administrator and the users will be able to interact with both machines without having to use IP addresses that can be difficult to memorize or that might even change.

What is a "Fully Qualified Domain Name"?

Fully Qualified Domain Name or FQDN literally means "fully qualified domain name" and 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 ":

  • university.edu could be an FQDN (assuming the domain was registered) allowing the network to be accessible from the internet.
  • computer1.university.edu* would also be an FQDN allowing the machine "computer1" 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 computer.

Change the hostname of a Linux (Ubuntu) server.

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

This manual assumes that you have superuser privileges. You may be required to use "sudo" before each command.

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

nano /etc/hostname.

This command will open a text editor that will allow you to edit the hostname. Once the changes have been made, simply 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 reboot.

hostname hostnameComputerName.

Using the "hostname" command you can change the hostname for the current session only. At the next reboot, the server will read again the name written in the "/etc/hostname" file. In any case, this command allows us to change the hostname without restarting the server, so it is suitable to apply the changes immediately.

3. Set the FQDN of the server.

It may be very desirable to set the FQDN of the server as well, allowing the server to know its own fully qualified name.

To do this, edit the "/etc/hosts" file: nano /etc/hosts.

Next, we will create a new entry with the following data: <ip-address> <hostname.domain.extension> <hostname>.

For example: 185.32.12.35 team1.university.edu team1

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

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

More than 2000 m² of own facilities and Data Centers in Spain
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.
More than 2000 m² of own facilities and Data Centers in Spain
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.