Hostname is a unique name assigned to a computer or device (printer, router, etc.) to identify it within a network. This name is important and used by many applications to be able to communicate effectively with the computer.
The hostname is essential within a local network because it allows to differentiation of the different devices that compose it. This allows the transfer of data and information within the network to flow smoothly.
You do not have to confuse Domain with Hostname because the domain refers to a name locally, but for the internet, we need additional information. So, a hostname is for local information and a domain makes it accessible from the internet, and the combination of both is an FQDN.
Changing the hostname in Debian 11
As Linux is a very flexible system, it is possible to change the hostname using several methods. So, you can always choose the easiest and most suitable for your needs, be it scripts or programs.
Method 1: using the hostnamectl command
hostnamectl command allows not only to change the hostname but also to query the host status. Therefore, to check the hostname, you can run
It should be noted that this command is present in all existing Linux distributions. You do not have to install anything.
If you run the above command, you will get an output screen like this:
Static hostname: desktop Icon name: computer-desktop Chassis: desktop Machine ID: 09143d0261be487380a9ec9bf41d5922 Boot ID: 06aaad4ceea14ce1bf95ee64c32530da Operating System: Linux Mint 20.3 Kernel: Linux 5.13.0-51-generic Architecture: x86-64
There is more information than we require, but the important thing is that the first line gives us the value of the hostname.
To change it, use this syntax.
sudo hostnamectl set-hostname [hostname]
sudo hostnamectl set-hostname imaginelinux
You can add the
--transient option to define whether it will be permanent or temporary.
Method 2: Using the sysctl command to change the hostname on Debian
-sysctl command allows you to modify kernel values directly. You can also use it to change the hostname. To achieve this, just run.
sudo sysctl kernel.hostname=[hostname].
sudo sysctl kernel.hostname=imaginelinux
That’s how fast and easy we can achieve the goal.
Method 3: Modifying the file /etc/hostname
/etc/hostname file contains the hostname value. So, another alternative is to modify it.
sudo nano /etc/hostname
And using the editor, change the value to your own. Save the changes and close the editor.
You also have to modify the
/etc/hosts file and modify everything that refers to the above hostname.
sudo nano /etc/hosts
To apply the changes, just restart the session or the computer.
Method 4: Change the Hostname on Debian with the hostname command
hostname command is also used to query the hostname and thus change it. To query the hostname.
And to change it, it is as simple as this:
This command only makes temporary changes. That is, when the system is restarted, they will be lost, and it will return to the previous name.
Changing the hostname can be simple and important on computers that are connected to a network. This allows applications to recognize it, improving communications and therefore the management of these.
I hope you liked the post, and you can support us by sharing the post with your friends.