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
Changing the hostname on Debian Linux
Changing the hostname on Debian Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Debian Linux
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - 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 hostnamectl command.

  1. First, let's check the current hostname by using either the hostname or hostnamectl command.
    $ 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.

  2. SUBSCRIBE TO NEWSLETTER
    Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


  3. 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 1 again to confirm the new change.
  4. Lastly, edit the /etc/hosts file 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
    
Editing the hosts file
Editing the hosts file

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.

  1. 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.
    # gnome-control-center
    
  2. loadposition in-article-ads-banner_2}
  3. Click on the Details tab at the bottom and then click on About.
  4. 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.
  5. Change the hostname via GUI
    Change the hostname via GUI
  6. Afterwards, type hostnamectl into 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
    

Closing Thoughts

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.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.