In this tutorial, we will show you how to change the hostname on Debian 10 Buster. For those of you who didn’t know, Hostname is a label used to identify the machine and will help you to easily distinguish the server from another one. The hostname should be a Fully Qualified Domain Name (FQDN) and should point to the server IP address so you can access the server by using it.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. If you are ready open up your terminal and follow through this tutorial, and in less than 10 minutes you will have changed your hostname on a Debian 10 (Buster) server.
Prerequisites
- A server running one of the following operating systems: Debian 10 (Buster)
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Change Hostname on Debian 10 Buster
Step 1. First I will check the current hostname by running “hostnamectl status
” on the shell of your server:
hostnamectl
The output on my system is:
Static hostname: godetz Icon name: computer-laptop Chassis: laptop Machine ID: 2381ec6bc9meilana1c843f399507ea2 Boot ID: 2902f9a594944feramona0759229ef0 Operating System: Debian GNU/Linux 10 (Buster) Kernel: Linux 4.15.0-43-generic Architecture: x86-64
Step 2. Change and Set Hostname.
To change the hostname type the command:
sudo hostnamectl set-hostname new_hostname ### example ### sudo hostnamectl set-hostname linuxtips
Check the hostname again (Close the session and open a new session using the terminal):
Static hostname: linuxtips Icon name: computer-laptop Chassis: laptop Machine ID: 2381ec6bcmeilanac843f399507ea2 Boot ID: 2902f9a594944fe28d8ac9075ramona0 Operating System: Debian GNU/Linux 9 (stretch) Kernel: Linux 4.15.0-43-generic Architecture: x86-64
In each of these configurations, you’ll need to be sure your hostname conforms to the standards for FQDNs (Fully Qualified Domain Names). The ASCII letters a – z, the digits 0 – 9, and the hyphen (‘-‘) are the only characters acceptable (the first character, however, cannot be a hyphen). You may also find it necessary (or useful) to include the domain name as well, in which case you would then also use periods (dots) to separate the hostname and the domain name (and top-level domain).
For more command options you can add the --help
flag at the end.
# hostnamectl --help hostnamectl [OPTIONS...] COMMAND ... Query or change system hostname. -h --help Show this help --version Show package version --no-ask-password Do not prompt for password -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container --transient Only set transient hostname --static Only set static hostname --pretty Only set pretty hostname Commands: status Show current hostname settings set-hostname NAME Set system hostname set-icon-name NAME Set icon name for host set-chassis NAME Set chassis type for host set-deployment NAME Set deployment environment for host set-location NAME Set location for host
Congratulations! You have successfully changed the hostname. Thanks for using this tutorial on how to change and set the hostname on your Debian 10 (Buster) system. For additional help or useful information, we recommend you check the official Debian website.