You can change the hostname on Debian 11/10 Linux using the following steps:
- Open a terminal and use the command
hostnamectl set-hostname new_hostnamewhere new_hostname is the new hostname you want to set. - Edit the file
/etc/hostsand change the old hostname to the new hostname in the line starting with127.0.1.1 - Edit the file
/etc/hostnameand change the old hostname to the new hostname - Restart the system or use the command
sudo systemctl restart systemd-hostnamedto apply the changes. - Verify the change by using the command
hostnamectlorhostname
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.