how to Debian Linux: Change Hostname / Computer Name Permanently

In Debian Linux, you can change the hostname or computer name permanently by editing the /etc/hostname file. Here are the steps:

  1. Open a terminal and log in as the root user or use sudo to run the following command.
sudo nano /etc/hostname
  1. Change the current hostname to the desired one.
  2. Save the changes by pressing CTRL + X, then Y and ENTER.
  3. Update the hosts file to reflect the new hostname.
sudo nano /etc/hosts
  1. Replace the old hostname with the new one in the line starting with 127.0.0.1.
  2. Save the changes by pressing CTRL + X, then Y and ENTER.
  3. Reboot the system to apply the changes.
sudo reboot

Please note that the hostname change will take effect only after a reboot.

Also some systems like systemd-based distro’s require you to use hostnamectl command to change the hostname instead of editing the files.

sudo hostnamectl set-hostname new_hostname

Leave a Comment