How to change hostname in Debian 10

When you finish installing the computer, configuring a friendly hostname will be one of the tasks that system administrators must perform.

In this article, I am going to show you how to change the host name on a Debian 10 computer.

How to display the current hostname?

If you want to know the current host name, run the following command on the terminal.

hostname

This will show you a short version of the hostname. To get the full version or FQDN (fully qualified domain name) of the host name, use this command:

hostname -f

As shown in the following screenshot, the short host name on my system is simply “debian”.

How to change hostname?

Open a terminal and log in as root. Run the following command to open the hostname file for changes.

nano /etc/hostname

Change host name in nano editor

Replace the old name with the new host name. A few general notes on choosing a host name:

  1. The hostname must be unique on your network. Therefore, do not use the host name twice.
  2. The host name must be lowercase.
  3. It is recommended to use only alphanumeric characters (a-z, 0-9) and “-” (minus character)

assume server1, save the changes and exit the editor.

Reboot the system for the changes to take effect. The following screenshot shows that the host name has been changed.

Debian host name

How to change hostname without rebooting Debian 10 computer?

Open a terminal with superuser rights and run the following command. Replace name-here with your server name.

hostname 

Then edit the host name file and update the host name.

nano /etc/hostname

Save and close the file.

Debian hosts file

Finally, open the hosts file and replace the old name with the new name. Lines should be read as follows.

127.0.1.1 your-old-host-name

Save and close the file.

How to change hostname in Debian 10

Sidebar