In Debian 12 and even in other operating systems hostname plays a quite important role. It helps the machine to get identified on a network. However, when we install OS, it sets the hostname automatically which sometimes needs to be personalized. In that case, to change the current hostname to the one we want, a user can either use the Graphical user interface or the command line terminal.
Here in this article, we learn various ways to update the hostname in Debian 12 Linux server or desktop.
1: Access the Terminal
If you are using a Graphical user interface then to change the Hostname using the terminal, we have to open it first. Go to Application and search “Terminal” as its icon appears, and click to open it.
2. To check the current hostname
As our system already has a pre-assigned hostname to check what it is, we have a command to run in a terminal, here is that.
3. Setting up Debian 12 Hostname – temporary
Well, if you don’t want your Debian 12 hostname to change permanently instead of just for the current session then that is possible as well. For that, in your command terminal type the given command:
sudo hostname new-one
Replace the new-one with the hostname you want to assign to your system temporarily. To see the changes, initialize your current environment or refresh your current session using:
4. Use hostnamectl set-hostname
Well, if you want to change your hostname permanently without rebooting your Debian 12 Linux, then use the “hostnamectl set-hostname” command.
sudo hostnamectl set-hostname new-one
To see the changes on your terminal, refresh the session:
5. Edit /etc/hostname and /etc/hosts
Another method to change the name of your computer is by editing two files – /etc/hostname and /etc/hosts. However, after editing these configuration files the user has to restart the system to apply them. This method is also permanent.
sudo nano /etc/hostname
You will see your existing hostname in the file, just change it to whatever you want to set. To save the file press Ctrl+O, hit the Enter key, and then to exit use Ctrl+X.
In the same way, also edit the host file and change your existing hostname in that as well. This file is used to map the hostnames to the IP address. This configuration is important when the user wants to resolve some IP address with the hostname.
sudo nano /etc/hosts
After editing and saving the files reboot your system.
6. Use GUI to Change the Debian 12 Hostname
Well, those who are not comfortable with the command-line method and using a graphical desktop can go for the GUI method.
- Go to the Debian 12 GUI Setting app.
- Select the About section given in the left side menu.
- Click on the Device Name
- Enter the new hostname you want to use.
- Click on Rename button to Save the changes
Enter your password when prompted.
Once the system restarts, the new hostname will be in effect.
Changing the hostname in Debian 12 is quite simple like Ubuntu and other Linux systems. You can use either Terminal or GUI whichever is suitable for you to customize and update the hostname. However, remember to choose a valid hostname, which means there must not be a space between the hostname you are setting up for your Debian 12 system.