Newsletter Subscribe
Enter your email address below and subscribe to our newsletter
A hostname is given to computers that are connected over a network, and with the help of a unique hostname, we can identify our system in a connected network. Generally, users are given the option to assign a hostname during the installation of Debian, but we can change it easily.
There are two types of hostnames static and transit. The static hostname is the default hostname which is stored at /etc/hostname, and transit is the temporary hostname that is changed on each boot. in this guide we are going to show you how to change the hostname in Debian 11.
As we are going to show you how you can change the hostname in Debian 11, but this is also applicable to each Debian-based Linux distribution, including Ubuntu, Linux Mint, Kubuntu, Pop_OS, LMDE, and many others.
But before showing you how to change the hostname in Debian, let’s see various ways how to identify the hostname of Debian.
Table of Contents
As we are going to show you multiple ways to change the hostname in Debian, we are also going to show you multiple ways to display the hostname in Debian. So let’s start with the first easiest way to identify the hostname in Debian.
This is the easiest way to identify the hostname of your Debian system. Just use the following command:
hostname
We can use the -f flag with the hostname command which will display FQDN (Fully Qualified Domain Name). Use the following command to show the hostname with FQDN:
hostname -f
If you don’t want to use the -f flag to show FQDN (Fully Qualified Domain Name), you can use –fqdn which will give us the same results as intended with the -f flag. Use the following command to show the hostname using –fqdn:
hostname –fqdn
If you want to know your hostname with other details such as hostname, chassis type, machine id, operating system details, kernel, and architecture, use the following command to display the hostname with such details:
hostnamectl
As you can see, it has displayed many other details including the hostname.
Once we are done with multiple ways to display hostname as it is required on each step of changing hostname method, we can now proceed on how to change hostname in Debian with various methods. Let’s start with the easiest one.
This is the easiest way to change your hostname but it will only change the transit hostname, meaning it will be applied temporarily and you will get the default hostname once you reboot. Use the following steps to change the transit hostname.
To check the current hostname, use the following command to display the current hostname:
hostname
To change the hostname, users are required to follow the given command syntax:
sudo hostname {New Hostname}
As we are going to change the hostname to “geek”, we are going to use the following command:
sudo hostname geek
To verify whether we have changed our hostname successfully or not, open the second window of Terminal and use the following command:
hostname
As you can see, we have changed the hostname from debian to geek.
This is the easiest way to change your hostname permanently using the hostnamectl command. Use the given steps and you will change your static hostname to make a permanent effect.
To check the current hostname, use the following command to display the current hostname:
hostname
To change the static hostname, users are required to follow the given command syntax:
sudo hostnamectl set-hostname {New Hostname}
As we are going to change our current hostname to “geek”, we are going to use the following command:
sudo hostnamectl set-hostname geek
To check whether we have changed the hostname successfully or not, open a new Terminal window use the following command:
hostname
As you can see, we have changed the hostname from “debian” to “geek”.
This is yet another way to change the static command of your Debian system. In this method, we are going to use the nmcli command to make permanent changes. Follow the given steps to change your hostname.
To check out the current hostname, use the following command:
hostname
To change the hostname permanently using nmcli, users are required to follow the given command syntax:
sudo nmcli general hostname {New Hostname}
As we are going to change our hostname from “debian” to “geek”, we are going to use the following command:
sudo nmcli general hostname geek
Once we have changed our hostname using the nmcli command, we can check it by reopening Terminal and using the following command:
hostname
Using this method you can change the hostname temporarily as it only changes the transit hostname which will be changed to default once you reboot. To change the hostname using sysctl, use the following steps.
As we are going to change the hostname and in the end, we are also going to verify changes, it is essential to know the current hostname by the following command:
hostname
The sysctl command will modify data in the kernel to apply changes. To change the hostname temporarily, use the following command structure:
sudo sysctl kernel.hostname={New Hostname}
As we are going to change our current hostname to “geek”, we are required to use the following command:
sudo sysctl kernel.hostname=geek
After changing our hostname using the sysctl command, let’s verify whether we have changed our hostname successfully or not with the following command:
hostname
This is yet another way to change your hostname with permanent effect. This method involves a direct change in the hostname configuration file. It may sound complex but don’t worry, just follows the given steps and you will be able to change your hostname successfully.
The configuration file of the hostname is located at /etc/hostname. To make changes, we are required to open it by the following command:
sudo nano /etc/hostname
It will open the configuration file with the current hostname. In our case, it is showing us “debian” as the current hostname.
To change your hostname, you will have to replace your current hostname with your desired one. In our case, we are going to change “debian” with “geek”.
To save changes, use CTRL + O, and to close the configuration file, use CTRL + X.
Reboot your system to apply the changes that we have just made.
Once you reboot your system, use the following command to verify whether we have successfully changed the hostname or not:
hostname
The nmtui command enables users to change their IP Addresses and hostname also. We are going to show you how you can change the hostname using nmtui by following the steps.
To know the current hostname of your system, use the following command:
hostname
The nmtui (Network Manager Tool User Interface) provides users with a graphical user interface by which we can perform operations. Use the following command to start nmtui:
nmtui
It will open a prompt with several options. Choose the “Set system hostname” option.
Now, enter your desired hostname. We are going with “geek” as our new hostname. Hit Enter after entering the hostname.
It will notify its user that the hostname has been changed.
Exit nmtui by choosing the “Quit” option.
Once we change hostname with nmtui, reopen Terminal and use the following command and if it shows a recently changed hostname, we have successfully changed hostname:
hostname
You can easily find your hostname using this command: hostname
To change your hostname, you have to use the following command: sudo hostnamectl set-hostname {New Hostname}
Changing the hostname in Debian is quite easy if you follow the given guide on how to change the hostname in Debian 11. We have used Debian 11 to demonstrate the process but the whole guide is also applicable to all the Debian-based distros such as Ubuntu, Linux Mint, and many others.