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:
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:
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:
Step 2: Change Hostname
Run the below mentioned command to change Hostname to “linuxhint” using “hostnamectl”:
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:
Step 2: Change Hostname
Another way to change Hostname is using nmcli(network manager command line interface) command by below mentioned command:
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:
Step2: Change Hostname
Run the below mentioned command, to change Hostname using nmtui command:
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:
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:
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:
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.