When you are done installing a machine, setting up a user-friendly and meaningful hostname is one of the task system administrators need to do.
In this article, I am going to show you how to change the hostname on Debian 10 machine.
How to Display the Current Hostname?
If you want to find out the current hostname, execute the following command on the terminal.
hostname
This will show you the short version of the hostname. To get the full or FQDN (fully qualified domain name) version of the hostname, use this command:
hostname -f
As shown in the following screenshot, the short hostname on my system is just “debian”.
How to Change the Hostname?
Open the terminal and login with root. Execute the following command to open the hostname file for changes.
nano /etc/hostname
Replace the old name with a new hostname. A few general notes to choosing a hostname:
- The hostname should be unique in your network. So don’t use the hostname twice.
- The hostname should be lowercase.
- It is recommended to use just alphanumeric characters (a-z, 0-9) and the “-” (minus char)
Suppose server1, save the changes and exit the editor.
Reboot the system so that changes can take effect. The following screenshot shows that the hostname has been changed.
How to Change the Host Name Without Restarting the Debian 10 Machine?
Open the terminal with root privileges and execute the following command. Replace name-here with the name of your server.
hostname <name-here>
Next, edit the hostname file and update the hostname.
nano /etc/hostname
Save and close the file.
Finally, open the hosts’ file and replace the old name with the new name. The lines should be read as follows.
127.0.1.1 your-old-host-name
Save and close the file.