Debian

How to Change Hostname on Debian 11

Hostname is usually given to computers attached to a network, it uniquely identifies your system over the network. In Debian (Linux OS), hostname is usually set during the installation of the system but you can change your Hostname even after the installation by different approaches. In this Article, various methods to change Hostname are discussed in detail.

The “static” host name is default hostname, maintained in the /etc/hostname file and can be selected by the user. The “transient” hostname is a dynamic hostname that the kernel keeps track of and assigned to the machine by services like DHCP or mDNS after it boots up.

You can follow any of the one method from 6 methods mentioned below to change Hostname in Debian 11:

  • Changing Hostname by using “hostname” command
  • Changing Hostname by using “hostnamectl” command
  • Changing Hostname by using “nmcli” command
  • Changing Hostname by using “nmtui” command
  • Changing Hostname using sysctl command
  • Changing Hostname in /etc/hostname file

Method 1: How to change Hostname by using “hostname” command

The “hostname” command changes the transient host name.

Step 1: Check current Hostname

Check the current hostname by below mentioned command:

$ hostname

Step 2: Change Hostname

Simplest way to change Hostname in Debian 11 is using hostname command, to change hostname to linuxhint run the below mentioned command:

$ sudo hostname linuxhint

You have to open new terminal to make it work:

So, the hostname is successfully changed. Note that this command only changes the hostname temporarily, which will be gone after restart.

Method 2: How to change Hostname by using “hostnamectl” command

The simplest and standard method to change/set Hostname permanently is using the “hostnamectl” command. Follow the steps below to successfully change Hostname using this command.

The “hostnamectl” command changes the static host name of the system.

Step 1: Check current Hostname

To check for present Hostname run the below mentioned command:

$ hostnamectl

Step 2: Change Hostname

Run the below mentioned command to change Hostname to “linuxhint” using “hostnamectl”:

$ sudo hostnamectl set-hostname linuxhint

To view the changed Hostname on terminal, you need to open new terminal as shown below:

Method 3: How to change Hostname using nmcli command

The “nmcli” command changes the static host name of the system.

Step 1: Check current Hostname

Check the current hostname by below mentioned command:

$ hostname

Step 2: Change Hostname

Another way to change Hostname is using nmcli(network manager command line interface) command by below mentioned command:

$ sudo nmcli general hostname linuxhint

Change “linuxhint” to hostname which you want to set:

You have to open new terminal to make it work:

So, the hostname is successfully changed.

Method 4: How to change Hostname using nmtui command

The “nmtuil” command changes the static hostname of the system.

One of the possible ways to change Hostname in your Debian system is using nmtui(network manager tool user interface) command.

Step1: Check current Hostname

Check the current hostname by below mentioned command:

$ hostname

Step2: Change Hostname

Run the below mentioned command, to change Hostname using nmtui command:

$ nmtui

A dialogue box will pop up on screen, select “Set system hostname” and press Enter from keyboard”:

After clicking on Set system hostname, a new dialogue box will appear with a tab , enter the Hostname which you want to set, here I am changing my hostname from alishba to linuxhint as shown below and then select “OK” option:

Authentication Required dialogue box will appear enter your sudo password there and click on “Authenticate”:

Then again confirmation dialogue box will appear, press enter from keyboard to change the hostname:

In the Network Manager TUI dialogue box, go to “OK” option and press Enter from keyboard to finish changing of Hostname:

Now you need to close the terminal and reopen it to apply changes:

So, the hostname has successfully changed.

Method 5: How to change Hostname using sysctl command

The “sysctl” command changes the transient hostname.

Step1: Check current Hostname:

Check the current hostname by below mentioned command:

$ hostname

Step2: Change Hostname

The sysctl is a command of Linux which modifies thing in kernel. You can also change the Hostname using sysctl command by below mentioned command:

$ sudo sysctl kernel.hostname=linuxhint

Replace “linuxhint” with Hostname you want to set:

You have to open new terminal to make it work:

So, the hostname is successfully changed.

Method 6: How to Change Hostname in /etc/hostname file

This method changes the static hostname.

Step 1: Open file

First you need to open “/etc/hostname” file using nano command as mentioned below:

$ sudo nano /etc/hostname

Step 2: Update Hostname in file

Now change the Hostname in file which you want to set, like I will write “linuxhint” as my new Hostname:

Press Ctrl+s to save and Ctrl+x to exit.

You need to reboot your system to apply changes:

So, the hostname has changed.

Conclusion:

During the installation of Debian11, you need a Hostname but if due to some reasons you want to change the hostname, there are several ways you can change Hostname after installation. In this article 6 possible methods with example are discussed to change Hostname on Debian 11; change Hostname by “hostname command, by “hostnamectl” command, by “nmcli” command, by “nmtui” command, by “sysctl” command and by changing Hostname in “/etc/hostname” file. You can follow any of the approaches explained to successfully change Hostname on your system.

About the author

Alishba Iftikhar

I am currently an undergraduate student in my 1st year. I am an internee author with Linuxhint and loved learning the art of technical content writing from senior authors. I am looking forward to opting my career as a full time Linux writer after I graduate.