In this tutorial, we will show you how to change the hostname on Debian 11. For those of you who didn’t know, In Linux, the hostname is the name assigned to a computer, typically in a networked environment. The hostname is used to identify the computer on the network and can be used to resolve domain names to IP addresses.
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. I will show you the step-by-step change of hostname on a Debian 11 (Bullseye).
Prerequisites
- A server running one of the following operating systems: Debian-based.
- 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).
- An active internet connection.
- 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 11
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update sudo apt upgrade
Step 2. Checking the Current Hostname.
The first step in changing the hostname is to check the current hostname of your system. You can do this by opening a terminal window and typing the following command:
hostnamectl
Step 3. Change the Hostname on Debian 11.
The hostname of a system is stored in a file called /etc/hostname
. To change the hostname, we will first need to open the hostname file using a favorite text editor:
nano /etc/hostname
Replace the current hostname value with the new desired name you want to assign. For example:
debian-meilana
Save the changes and exit the text editor, then reboot to apply the changes you made to the hostname of your Debian device:
reboot
Step 4. Verifying the New Hostname.
After you have rebooted your system, you can verify that the new hostname has been set by using the following command:
hostnamectl
Output:
Static hostname: debian-meilana Icon name: computer-vm Chassis: vm Machine ID: g0detzd8352c404898f47e005627888 Boot ID: 9a12f2136ba74g0detz8bc83786888 Virtualization: kvm Operating System: Debian GNU/Linux 11 (bullseye) Kernel: Linux 5.16.0-8-amd64 Architecture: x86-64
Congratulations! You have successfully changed the hostname. Thanks for using this tutorial to set or change the hostname on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Debian website.