How to Change Hostname on Debian 10
Displaying the Current Hostname
To find out your current system name by running the following command.
hostnamectl
Output:
root@vps:~# hostnamectl
Static hostname: vps.server.com
Icon name: computer-vm
Chassis: vm
Machine ID: 0f36b9c3337c53d482fa026f60c21da5
Boot ID: 8d91624669e94c509e5808af0d4da242
Virtualization: kvm
Operating System: Debian GNU/Linux 10 (buster)
Kernel: Linux 4.19.0-13-amd64
Architecture: x86-64
Changing the System Hostname
Now that you know the current hostname, you can change the hostname by using the following command and Optionally you can also set the pretty hostname as follows.
hostnamectl set-hostname crowncloud.net
hostnamectl set-hostname "crowncloud production server" --pretty
And also /etc/hosts file should be edited to successfully change Debian server name.
vi /etc/hosts
Output:
127.0.0.1 localhost
127.0.0.1 crowncloud.net
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Then replace the old name with the new, then save the file and exit.
Ubuntu servers might need to install cloud-init. If it is installed you will also need to edit the cloud.cfg file.
apt install cloud-init
Once the cloud-init is installed need to find "preserve_hostname: false" line in the follwoing configuration file "/etc/cloud/cloud.cfg" and change it to true.
vi /etc/cloud/cloud.cfg
preserve_hostname: true
Save the file and exit,
Verify the change
To verify the hostname has been fully changed, enter the "hostnamectl" command:
hostnamectl
Output:
root@vps:~# hostnamectl
Static hostname: crowncloud.net
Pretty hostname: crowncloud production server
Icon name: computer-vm
Chassis: vm
Machine ID: 0f36b9c3337c53d482fa026f60c21da5
Boot ID: 8d91624669e94c509e5808af0d4da242
Virtualization: kvm
Operating System: Debian GNU/Linux 10 (buster)
Kernel: Linux 4.19.0-13-amd64
Architecture: x86-64