How to change hostname on Debian 11/10 Linux

You can change the hostname on Debian 11/10 Linux using the following steps:

  1. Open a terminal and use the command hostnamectl set-hostname new_hostname where new_hostname is the new hostname you want to set.
  2. Edit the file /etc/hosts and change the old hostname to the new hostname in the line starting with 127.0.1.1
  3. Edit the file /etc/hostname and change the old hostname to the new hostname
  4. Restart the system or use the command sudo systemctl restart systemd-hostnamed to apply the changes.
  5. Verify the change by using the command hostnamectl or hostname

It is important to note that changing the hostname does not change the system’s hostname permanently, it will only be temporary and will change back to the original name after reboot. To make the changes permanent you need to edit the file /etc/cloud/cloud.cfg and change the parameter preserve_hostname from false to true

Make sure that you also update the hostname in any configuration files or scripts that refer to it.

Leave a Comment