The hostname of a Linux system is important because it’s used to identify the device on a network. The hostname is also shown in other prominent places, such as in the terminal prompt. This gives you a constant reminder of which system you’re working with. It’s a real life saver when you’re managing multiple systems through SSH and those command line terminals start to blend together in your mind.
Of course, IP addresses are used when devices need to communicate with each other, but those can change frequently. Hostnames give us a way to know which device we’re interacting with either on the network or physically, without remembering a bunch of numbers that are subject to change. Thus, it’s important that your system bears a hostname which helps you to identify it quickly. For example, “backup-server” is much more informative than “server2.” If you can’t easily identify a system’s purpose from the hostname, it’s time to change it.
In this guide, we’ll show you how to change the hostname on Debian Linux. Changing the hostname can be done either by command line or GUI, and we’ll show you the steps for both methods below.
In this tutorial you will learn:
- How to change the Debian hostname from command line
- How to change the Debian hostname from GNOME GUI
|Category||Requirements, Conventions or Software Version Used|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Change Debian hostname from command line
Use the following steps to change Debian’s hostname using systemd’s
- First, let’s check the current hostname by using either the
$ hostname debian $ hostnamectl Static hostname: debian Icon name: computer-vm Chassis: vm Machine ID: 37eaf1edf1864dee9cfa90373206a449 Boot ID: f4d3980df9da46f5b1a5dc997739f8b1 Virtualization: oracle Operating System: Debian GNU/Linux 10 (buster) Kernel: Linux 4.19.0-16-amd64 Architecture: x86-64
Both commands indicate that our hostname is
debian, the default hostname for new Debian installations.
- Next, change the hostname with the following command. In this example, we’ll change our hostname to
linuxconfig. You’ll be prompted for the administrator password when executing this command.
$ hostnamectl set-hostname linuxconfig
Run the commands from
Step 1again to confirm the new change.
- Lastly, edit the
/etc/hostsfile to reflect the change. For example:
Add the following two lines to your file, replacing this example with your desired hostname. You can leave the existing, default lines in the file as well.
127.0.0.1 linuxconfig ::1 linuxconfig
That’s all there is to it. Note that your currently opened terminals will not yet reflect the change, but newly opened terminals will.
Change hostname from GNOME GUI
If you have GNOME GUI installed on Debian, you can use the following steps to change the system’s hostname.
- Debian doesn’t let a normal user edit the hostname from GUI, so we’ll need to open the GNOME settings menu with our root account. To do this, run the following command as root.
- Click on the Details tab at the bottom and then click on About.
- In this menu, you can click the area titled ‘Device Name’ and enter your desired hostname. Just press enter once you’re done with the change, and then you can close this window.
- Afterwards, type
hostnamectlinto the terminal you have opened so you can verify that the change was made.
# hostnamectl Static hostname: linuxconfig Icon name: computer-vm Chassis: vm Machine ID: 37eaf1edf1864dee9cfa90373206a449 Boot ID: f4d3980df9da46f5b1a5dc997739f8b1 Virtualization: oracle Operating System: Debian GNU/Linux 10 (buster) Kernel: Linux 4.19.0-16-amd64 Architecture: x86-64
In this guide, we saw a command line and GUI method for changing the system hostname in Debian Linux. We also learned about the importance of picking an applicable hostname to assist in the easy identification of a system. Administrators can use these methods to ensure that their Debian computers have appropriate and easily identifiable hostnames.