How to Change Hostname on Debian 10 Linux
Updated on
•6 min read

This tutorial explains how to change the hostname on Debian 10 Buster without restarting the system.
The hostname is set at the time when the Debian operating system is installed or if you are spinning up a virtual machine it is dynamically assigned to the instance at startup.
Prerequisites
To be able to change the system hostname you need to be logged in as root or user with sudo privileges .
Display the Current Hostname
In Debian 10 and all other Linux distributions using systemd
, you can change and display the hostname of a given system with the hostnamectl
tool.
To view the current system hostname, type hostnamectl
without any option:
hostnamectl
The output will show the current system hostname, in this example that is host.linuxize.com
.
Static hostname: host.linuxize.com
Icon name: computer-vm
Chassis: vm
Machine ID: 70a3f06298014fd9ac42e5dc1de1034a
Boot ID: 1dc8b9af89a4426b99cb348f6d483757
Virtualization: oracle
Operating System: Debian GNU/Linux 10 (buster)
Kernel: Linux 4.19.0-5-amd64
Architecture: x86-64
Change the System Hostname
A hostname is a label that identifies a machine on the network. You shouldn’t set the same hostname on two different machines on a same network. It is recommended to use a fully-qualified domain name (FQDN
) as the system hostname.
There are two steps involved when changing the system hostname on Debian 10. First, set the new hostname using the hostnamectl set-hostname
command followed by the desired hostname and then update the /etc/hosts
file with the new hostname.
For example, to change the system hostname to arya.example.com
, you would do the following steps:
First set the new hostname by running:
sudo hostnamectl set-hostname arya.example.com
The
hostnamectl
command does not produce output. On success, 0 is returned, a non-zero failure code otherwise.Second, open the
/etc/hosts
file and replace the old hostname with the new one./etc/hosts127.0.0.1 localhost 127.0.0.1 arya.example.com arya # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters
Verify the Change
To verify that the hostname was successfully changed, once again use the hostnamectl
command:
hostnamectl
The new system hostname will be printed on the command line.
Static hostname: arya.example.com
Icon name: computer-vm
Chassis: vm
Machine ID: 70a3f06298014fd9ac42e5dc1de1034a
Boot ID: 1dc8b9af89a4426b99cb348f6d483757
Virtualization: oracle
Operating System: Debian GNU/Linux 10 (buster)
Kernel: Linux 4.19.0-5-amd64
Architecture: x86-64
Conclusion
Changing system hostname on Debian 10 Buster is an easy task, involving only two simple steps.
Feel free to leave a comment if you have any questions.