Categories: DebianLinuxShell

How to Change the Hostname on Debian Linux

The computer name or the hostname of a system is used to identify your computer or server on a network. This can be a local network (LAN) or the internet. 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 to achieve this.

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 Debian 10 and Debian 11.

Changing the hostname on Debian

Method 1: 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

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.

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

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

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 2: 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

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.

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

Method 3: Through the GUI

To change the 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.

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

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:

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.

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 a permanent way of changing the computer name.

Vitux Staff

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago