How to change hostname on Debian 11/10 Linux
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
/etc/cloud/cloud.cfg and change the parameter preserve_hostname from false to trueMake sure that you also update the hostname in any configuration files or scripts that refer to it.
