Enter your email address below and subscribe to our newsletter

How to Change Hostname in Debian 11

Share your love

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. 

Ubuntu Vs Debian

How to Identify Hostname in Debian

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.

Method 1: Identify Hostname Using Hostname Command

This is the easiest way to identify the hostname of your Debian system. Just use the following command:

 hostname 

1. hostname

Method 2: Identify Hostname Using -f Flag

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 

1.1 hostname -f

Method 3: Identify Hostname Using –fqdn Command

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 

1.2 hostname --fqdn

Method 4: Display Hostname Including other Details

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 

1.3 hostnamectl

As you can see, it has displayed many other details including the hostname.

Changing Hostname in Debian

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.

Method 1: Change Hostname Using hostname Command

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.

Step 1: Verify Current Hostname

To check the current hostname, use the following command to display the current hostname:

 hostname 

2. hostname

Step 2: Changing Current 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 

2.1 sudo hostname geek

Step 3: Verifying Changed Hostname

To verify whether we have changed our hostname successfully or not, open the second window of Terminal and use the following command:

 hostname 

2.2 hostname with geek

As you can see, we have changed the hostname from debian to geek.

Method 2: Change Hostname Using hostnamectl Command

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.

Step 1: Verify Current Hostname

To check the current hostname, use the following command to display the current hostname:

 hostname 

3. hostname

Step 2: Changing Hostname Permanently

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 

3.1 sudo hostnamectl set-hostname geek

Step 3: Verify Changes

To check whether we have changed the hostname successfully or not, open a new Terminal window use the following command:

 hostname 

3.2 hostname with geek

As you can see, we have changed the hostname from “debian” to “geek”.

Method 3: Change Hostname Using nmcli Command

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.

Step 1: Verify Current Hostname

To check out the current hostname, use the following command:

 hostname 

4. hostname

Step 2: Change Hostname Using nmcli Command

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 

4.1 sudo nmcli general hostname geek

Step 3: Verifying Changes

Once we have changed our hostname using the nmcli command, we can check it by reopening Terminal and using the following command:

 hostname 

4.2 hostname geek

Method 4: Change Hostname Using sysctl Command

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.

Step 1: Check Current Hostname

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 

5. hostname

Step 2: Change Hostname Temporarily Using sysctl

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 

5.1 sudo sysctl kernel.hostname=geek

Step 3: Verifying Changes

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 

5.2 hostname

Method 5: Change Hostname Using Configuration File

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.

Step 1: Open Hostname Configuration File

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 

6. sudo nano hostname

It will open the configuration file with the current hostname. In our case, it is showing us “debian” as the current hostname.

6.1 showing default hostname

Step 2: Changing Hostname in Configuration File

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”.

6.2 changed hostname in config file

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.

Step 3: Verifying Changes

Once you reboot your system, use the following command to verify whether we have successfully changed the hostname or not:

 hostname 

6.3 hostname chamged

Method 6: Change Hostname Using nmtui Command

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.

Step 1: Check Current Hostname

To know the current hostname of your system, use the following command:

 hostname 

7. hostname

Step 2: Using nmtui to change 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 

7.1 nmtui

It will open a prompt with several options. Choose the “Set system hostname” option.

7.2 select set hostname option

Now, enter your desired hostname. We are going with “geek” as our new hostname. Hit Enter after entering the hostname.

7.3 choose geek as hostname

It will notify its user that the hostname has been changed.7.4 set hostname to geek notice

Exit nmtui by choosing the “Quit” option.

7.5 quit nmtui

 

Step 3: Verifying Hostname

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 

7.6 hostname chamged

Frequently asked questions related to changing Hostname

How do I find my hostname Debian 10?

You can easily find your hostname using this command: hostname

How do I change the hostname in Debian 10?

To change your hostname, you have to use the following command: sudo hostnamectl set-hostname {New Hostname}

Conclusion

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.

Share your love
Sagar Sharma
Sagar Sharma

Sagar always uses Linux to its core and loves to write the technical side of system administration! While he's not writing for GeniusGeeks, you can find him writing for core linux blogs like IT'SFOSS.com and LinuxHandBook.com

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!