Debian 9 change hostname is done very similarly to the previous Debian versions. With one major difference. It is how you apply the changes. If you don’t apply the changes, the changes will not be taken into effect until you reboot or restart your system. The same way if you use the hostname commands to change the hostname, the hostname is reverted when you reboot. Let us see how to Debian 9 change hostname permanently.
In the following example, let us assume the server name is example.server.com.
Debian 9 change hostname permanently
If you run the command hostname, it will return example. That is the hostname of your system.
root@example:~# hostname
example
Domain Name
When adding the parameter -d to the hostname command it will give you the domain name currently set for your system.
root@example:~# hostname -d
server.com
FQDN / Fully Qualified Domain Name
Change the parameter to -f and you get the FQDN or Fully Qualified Domain Name instead. Here is an example.
root@example:~# hostname -f
example.server.com
Change the hostname
To change the hostname you need to edit the /etc/hostname file. If you use the hostname command, it will not be permanent. The hostname file will only contain the hostname. The picture below is from one of my database servers.
Change the Domain or FQDN
Any changes to the domain name or the FQDN has to be done in the /etc/hosts file. Here is an example of how a hosts file looks. Again from my database server.
Apply the changes
As mentioned above the changes needs to be applied, like restarting or reloading the hostname service. If not the changes will not be applied until you reboot or restart your system.
This is how you apply the settings on a Debian 9 system:
sudo hostname -F /etc/hostname
If you are looking for how to change hostname, domain or fqdn on Debian 8 or earlier, check out Debian – Change hostname, domain or FQDN permanently. Or looking for how to change the hostname on an Ubuntu system permanent.
Check out the video below to see how it works.
That is how Debian 9 change hostname works.