In Debian Linux, you can change the hostname or computer name permanently by editing the /etc/hostname
file. Here are the steps:
- Open a terminal and log in as the root user or use
sudo
to run the following command.
sudo nano /etc/hostname
- Change the current hostname to the desired one.
- Save the changes by pressing
CTRL + X
, thenY
andENTER
. - Update the hosts file to reflect the new hostname.
sudo nano /etc/hosts
- Replace the old hostname with the new one in the line starting with
127.0.0.1
. - Save the changes by pressing
CTRL + X
, thenY
andENTER
. - 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