In this article, you will find:
How to Change Hostname in Debian 12
How to Change Hostname in Debian 12
You can change hostname in Debian 12 from:
How to Change Hostname in Debian 12 from Terminal
To change hostname in Debian 12 from the terminal, you can use:
Let’s discuss each method in the below-sections of this guide.
How to Change Hostname in Debian 12 from Terminal Using hostnamectl Command
The hostnamectl is a systemd command that manages your system hostname and related settings. You can use the hostnamectl command to change hostname in Debian 12. This can be done by using the hostnamectl command followed by the set-hostname keyword and new hostname according to your choice:
After changing the hostname, use the following command to apply changes to the hostname on the terminal:
You can confirm whether the hostname changed through this method is static by running the below-given command:
Note: The static hostname will remain the same if you reboot your system.
How to Change Hostname in Debian 12 from Terminal Using hostname Command
The hostname command is a widely used to find the hostname on a Linux system. Besides finding the hostname, you can also use the hostname command with sudo privileges followed by the new hostname to change hostname on Debian system:
To apply the changes on the terminal, you can use:
Note: The hostname changed through the hostname command will not remain static, and the changes will be reverted once you reboot the system. You can verify it by running the following command:
How to Change Hostname in Debian 12 from Terminal Using nmcli Command
The nmcli command on Debian 12 is used to manage network related settings, such as activating/deactivating, or changing/editing the network connections. Besides that, you can also use the nmcli command to change hostname in Debian 12. You must use the nmcli command with sudo privileges followed by the general and hostname keywords then new hostname that you want to change on the system:
Once the hostname is changed, you can apply changes to the terminal using the following command:
Then verify whether the hostname is static using the following command:
How to Change Hostname in Debian 12 from Terminal Using sysctl Command
The sysctl command allows Debian users to tweak the system settings and control the working of your computer, including handling network traffic, managing memory and more. Besides that, the sysctl command can also be used to change hostname in Debian 12. However, similar to the hostname command, this command will not set the static hostname on your Debian system.
To use sysctl command on Debian 12, run it with sudo privileges, use kernel.hostname object keyword and pass your new host name as a value to this keyword:
Once done, use the following command to apply changing the hostname on the terminal as well:
You can then verify whether the hostname is static or transient using the following command :
How to Change Hostname in Debian 12 from Terminal Using nmtui Command
nmtui is a Network Manager Terminal User Interface that allows you to change your hostname on Debian 12. You can open Network Manager (TUI) on the terminal from the following command:
There, select the Set system hostname option:
Change your hostname according to your choice and use OK button to confirm the changes:
Then use the Quit option to exit back to the terminal:
After changing the hostname, apply the changes to the terminal using:
Then verify whether the hostname is static using:
How to Change Hostname in Debian 12 from Terminal Using /etc/hostname File
There is also a hostname text file that is located in the /etc directory of your Debian system. This file contains a single line of text that is basically the hostname of your system. If you want to change hostname in Debian 12 from this /etc/hostname file, you must first open it on the terminal using nano editor through the following command:
Then inside this file, just change hostname according to your choice, and save it using CTRL+X, add Y and press Enter.
The hostname from this method will change on the terminal after you reboot your system, here newgrp command will not work:
How to Change Hostname in Debian 12 from GUI
By default, Debian users will not be able to change hostname from GUI if entered the settings with a normal user. This case will be different for the users if they are using a different desktop environment for Debian 12. Some desktop environments like GNOME and KDE may not allow users to change hostname from GUI, but you can change hostname from GUI if you are using LXDE or Xfce desktop environment.
You can change hostname in Debian 12 from GUI using the following steps:
Step 1: First login as a root user from terminal :
Step 2: Then execute the following command to open Debian Settings:
Note: You can skip the above steps and try whether you can change hostname on Debian 12 without login as a root user on your Debian system using the below-given steps.
Step 3: Scroll down, navigate to About section and click on the Device Name:
Step 4: Change the hostname and then select the Rename button to save the changes:
Step 5: Apply changes to the terminal using:
Step 6: After that, use the following command to verify whether the hostname changed through the GUI is static or transient:
Note: You can also change hostname on Debian 12 from the Sharing option as well by renaming the previous hostname with the new one. However, again this option may or may not work on your Debian system.
Conclusion
Changing hostname on Debian 12 is a straightforward task that can be done from the commands like hostnamectl, hostname, nmcli, sysctl, and nmtui. Besides that, you can also change hostname from the hostname file located in the /etc directory. Further, you can also open the Settings on GUI and change the hostname from About or Sharing sections. However, you may have to enter the user as a root if you are going to use the About option. While the Sharing option may or may not work on some system users due to different desktop environments.