A hostname is a name given to a computer that is connected to a network. It identifies your system on the network. The hostname in Debian is normally set during the OS installation, although you can change it later using several methods.
We will discuss the different ways of changing the hostname on Debian 11 Bullseye Distribution in this article.
How to change the hostname in Debian 11?
You can change the hostname of your Debian system by using different ways that we have listed:
Change hostname using the hostname command
The easiest method to change the hostname of a Linux system is by using the ‘hostname’ command. However, it is important to note that this method will temporarily change the hostname. The hostname changes are set to default on the system reboot.
To change or set the hostname in Debian 11, use the ‘hostname’ command in the following way:
$ sudo hostname newhost_name
For example, if you want to change the hostname ‘Debian11-distro’ then, replace the ‘newhost_name’ with your hostname ‘Debian11-distro’.
$ sudo hostname Debian11-distro
To view the updated hostname, use this command:
Change hostname using hostnamectl command
If you want to change the hostname permanently, in this case, this method is the most commonly used method for permanently changing the hostname on all Linux distributions.
The ‘hostnamectl’ command permanently changes the hostname in Debian 11.
$ sudo hostnamectl set-hostname Debian11-distro
To view the updated hostname, restart the system and use this command on the
If you want to display the hostname only, use the ‘–static’ flag with the hostnamectl command.
$ hostnamectl –static
Change hostname using the sysctl command
The ‘sysctl’ command also allows you to change the hostname in Debian11-PC.
$ sudo sysctl kernel.hostname=Debian11-PC
Restart your system to view the changes.
Using the nmcli command
The nmcli (network manager command-line interface) tool helps you to control the NetworkManager. Using the nmcli tool, we can easily change the hostname. Simply just run the nmcli command in the following order:
$ sudo nmcli general hostname Debian11-PC
Change hostname in /etc/hostname file
You can modify the hostname in the ‘/etc/hostname’ file. Open the file in your favorite text editor:
$ sudo nano /etc/hostname
Update the hostname by replacing the previous one in this file. Save all changes by pressing ‘Ctrl+O’ and ‘Ctrl+x’ to exit from the window.
Using nmtui utility
The ‘nmtui’ command allows you to change the hostname in Debian 11. Execute the ‘nmtui’ command in the terminal and the following dialogue will pop up on the terminal screen. Use the arrows keys for navigation and select the option ‘Set system hostname’. Now, press ‘Enter’ from your keyboard.
A new dialogue will pop up in the window. Enter the hostname name and select <OK>.
After authentication, press ‘Enter’ for confirmation.
Next, navigate into the ‘Quit’ option in the Network Manager TUI window and press ‘Enter’.
We explained different methods in this article about how to change the hostname in Debian 11. You can choose any method from all approaches that suit your needs.
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.