The computer name or the hostname of a system is used to identify it on the network. You are asked to set a computer name or hostname when you install your OS and it must be unique to avoid conflicts. Later when you want to change your computer name, you have to run some commands or make changes to some configuration files.

In this article, we will explain three ways to change your computer name, also known as hostname, through both the graphical user interface and the command line.

We have run the commands and procedures mentioned in this article on a Debian 10 OS.

Changing the hostname in Debian 10

Method 1: Through the GUI

To change hostname through GUI, click on the downward arrow in the top right corner of your Debian desktop. In the drop-down menu that appears, click on the Settings icon as shown below to launch the Settings utility.

Settings Icon

Alternatively, you can open the Settings utility from the system’s Dash menu. Press super key on your keyboard, then in the search bar, type settings. When the utility appears, click on it to open.

Open Settings

Now navigate to the Details tab from the left pane. You will see the device name or hostname in the About view as shown below:

About your computer

By doing so, your hostname will be changed. However, remember that changing the hostname through this method is not permanent. It will revert to the old name when you will restart your system.

Method 2: Through the hostname and hosts file

The computer name or hostname can also be changed using the hostname command. To view the current hostname, simply type hostname in the Terminal:

$ hostname

Hostname command

Now to change the computer name, use the following command syntax:

$ sudo hostname new_hostname

Replace new_hostname with the one you want to set for your system.

Set new hostname using hostname command on Debian 10

It is also a temporary way of changing the computer’s name. There is also a way to change the computer’s name permanently. For that, we will have to edit two different configuration files named the /etc/hostname and /etc/hosts file.

First, edit the /etc/hostname file by entering the following command in Terminal:

$ sudo nano /etc/hostname

Edit the /etc/hostname file

It will list your computer name. Change the computer’s name to a new name and then press Ctrl+O and Ctrl+X to save and exit the file simultaneously.

Then edit the /etc/hosts file as follows:

$ sudo nano /etc/hosts

You will see the computer’s name listed against the IP: 127.0.1.1

Edit the /etc/hosts file

Change this computer’s name to a new name and then save and exit the file using Ctrl+O and Ctrl+X simultaneously. Now the computer’s name you have just set will remain permanent even after you restart your system.

Method 3: Through the hostnamectl command

There is another command hostnamectl using which you can change your computer’s name.

Now just type hostnamectl in your Terminal. It will display detailed information about your system including the computer name or hostname.

$ hostnamectl

Get computer device name details using hostnamectl command

To change the computer’s hostname through the hostnamectl command, use the following syntax:

$ hostnamectl set-hostname "new_hostname"

Replace new_hostname with the one you want to set for your system.

Set new hostname using hostnamectl

Again run the systemctl command, now you will see the new hostname that you have set using the hostnamectl command.

Conclusion

In this article, we have learned how we can change the computer name in the Debian OS. Changing the computer name via GUI or hostname command are the temporary methods while editing the /etc/hostname and /etc/hosts configuration files provide the permanent way of changing the computer name.

How to change the Hostname in Debian 10
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn