How to change the hostname in Debian 10

s2 0

The computer name or host name of a system is used to identify it on the network. When you install your operating system, you will be asked to specify a computer name or host name, which must be unique to avoid conflicts. If you later want to change your computer name, you will need to run a few commands or make changes to some configuration files.

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

We ran the commands and procedures mentioned in this article on a Debian 10 operating system.

Changing the host name in Debian 10

Method 1: through the GUI

To change the host name through the GUI, click the down arrow in the upper right corner of your Debian desktop. In the drop-down menu that appears, click the Settings icon as shown below to open the settings Utility.

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

Now navigate to the details Tab from the left pane. You can see the device name or host name in the Above View as shown below:

Via your computer

This will change your host name. However, keep in mind that changing the hostname using this method is not permanent. It will revert to the old name when you restart your system.

Method 2: Via the host name and the hosts file

The computer name or host name can also be changed using the Hostname Command. To see the current host name, just enter Hostname in the terminal:

$ hostname

Hostname command

To now change the computer name, use the following command syntax:

$ sudo hostname new_hostname

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

Set a new hostname to Debian 10 using the hostname command

It is also a temporary way to change the name of the computer. There is also a way to permanently change the name of the computer. To do this, we need to edit two different configuration files named / etc / hostname and / etc / hosts File.

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

$ sudo nano /etc/hostname

Edit the / etc / hostname file

It will list your computer name. Change the name of the computer to a new name, and then press Ctrl + O and Ctrl + X to save and exit the file at the same time.

Then edit the / etc / hosts File as follows:

$ sudo nano /etc/hosts

You will see the name of the computer opposite the IP: 127.0.1.1

Edit the / etc / hosts file

Change the name of this computer to a new name, then save and exit the file with Ctrl + O and Ctrl + X simultaneously. The name of the computer that has just been set is now permanently retained even after the system has been restarted.

Method 3: Using the hostnamectl command

There is another order hostnamectl with which you can change the name of your computer.

Now just tap hostnamectl in your terminal. It shows detailed information about your system, including the computer name or host name.

$ hostnamectl

Get details about the computer device name using the hostnamectl command

How to change the host name of the computer using the hostnamectl Command use the following syntax:

$ hostnamectl set-hostname "new_hostname"

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

Set a new host name with hostnamectl

Run the systemctl command again. You will now see the new host name that you set with the hostnamectl command.

diploma

In this article we learned how to change the computer name in the Debian operating system. Changing the computer name using the GUI or the hostname command are the temporary methods, while editing the / etc / hostname and / etc / hosts configuration files provides the permanent way to change the computer name.

How to change the hostname in Debian 10