How to Change Hostname on Debian 11 or 10

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 change the hostname on Debian 11 Bullseye and Debian 10 Buster using the command line. 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.

Method 1: Change hostname with “hostnamectl.”

To change the hostname in Debian, the process starts with launching the terminal. To do so, you can either click on the terminal icon located in the application launcher. After opening the terminal; you will need to 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 edit the “/etc/hostname” file manually. 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 be:

debian-linux

To apply the changes you made to the hostname of your Debian device, you will need to restart the 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 as it 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.

FAQs on changing hostname on Debian:

Q: What is a hostname in Debian, and why is it important?

A: A hostname is a unique identifier assigned to a computer or device within a network. In Debian, the hostname helps differentiate your device from others within the network, making it easier to identify and manage.

Q: How can I check my current hostname in Debian?

A: To check your current hostname in Debian, open the terminal and execute the “hostname” command. The terminal will display your device’s current hostname.

Q: What is the recommended method for changing the hostname in Debian?

A: Debian’s recommended method for modifying the hostname is using the “hostnamectl set-hostname” command, which is more user-friendly and efficient.

Q: Do I need to restart the system after changing the hostname in Debian?

A: Yes, to apply the changes you made to the hostname, you will need to restart the system to ensure that the new hostname takes effect.

Q: Is it possible to set up a fully qualified domain name (FQDN) in Debian?

A: Yes, it is possible to set a fully qualified domain name (FQDN) in Debian by modifying the “/etc/hosts” file in addition to the “/etc/hostname” file. The FQDN includes the hostname and the domain name and is used to identify your device within a network.

Share to...