Modifying the network device’s hostname in a Linux system is an uncomplicated procedure that can be executed via the terminal. This tutorial will cover how to use the command line to change the hostname on Debian 12 Bookworm, Debian 11 Bullseye, and Debian 10 Buster. A hostname is a unique name allocated to a computer or device within a network and is used to differentiate it from other devices on the same network. Modifying the hostname can aid in identifying or customizing a specific network device.
Table of Contents
Method 1: Change hostname with “hostnamectl.”
The process starts with launching the terminal to change the hostname in Debian. To do so, you can either click on the terminal icon located in the application launcher. After opening the terminal, you must execute the command “sudo hostnamectl set-hostname new_hostname” to modify the hostname. Remember to replace “new_hostname” with the desired name you want to assign to your Debian device.
sudo hostnamectl set-hostname new-hostname
To modify the hostname of the Debian system, replace “new_hostname” in the “sudo hostnamectl set-hostname new_hostname” command with the desired hostname. This command will change the hostname of your Debian device to the specified value.
As an example, executing the following command will modify the hostname to “debian-linux”:
sudo hostnamectl set-hostname debian-linux
After modifying the hostname, close the terminal and open a new command line terminal to check if the changes have been applied successfully.
Method 2: Change Hostname with Hostname File
Another way to modify the Debian hostname is to manually edit the “/etc/hostname” file. By changing the hostname value in this file, you can set a new name for your system. First, open the hostname file with the nano text editor:
sudo nano /etc/hostname
Replace the current hostname value with the new desired name you want to assign to your Debian device. An example can, you will need to restart the system to:
debian-linux
To apply the changes you made to the hostname of your Debian system. After restarting, the new hostname will be updated and in effect.
reboot
Conclusion
To sum up, modifying the hostname on Debian can be accomplished either through the “hostnamectl set-hostname” command or by manually editing the “/etc/hostname” file. The “hostnamectl set-hostname” command is the preferred method, which is more efficient and user-friendly. However, if this command is unavailable on your system, then editing the “/etc/hostname” file is a viable alternative. After making the changes, remember to restart the system for the new hostname to take effect.