Oct 23, 2023 3 min read

How to Change Hostname on the Debian 11 Linux

Change hostname on debian 11 with our step-by-step tutorial.It is a label assigned to a device or server that helps identify it on a network.

Change Hostname on the Debian 11 Linux
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to change Hostname on Debian 11 Linux. Let’s briefly understand - What is a Hostname?

The hostname is mainly set at the time when the Debian operating system installation is there or if a user is spinning up a virtual machine then, it is dynamically assigned to instances at the startup.

In this tutorial, you will change the Hostname on Debian 11 Linux. We will also address some of the FAQs related to the Hostname.

Advantages of Changing Hostname on Debian 11

  1. Recognizability: Changing the hostname to a meaningful and recognizable name makes it easier to identify and manage the system within a network environment.
  2. Organizational Consistency: Setting a specific naming convention for hostnames allows for consistent identification and management across various systems.
  3. Improved Security: Changing the hostname can enhance security by assigning a unique and identifiable name, making it more difficult for unauthorized access or spoofing attempts.
  4. Network Troubleshooting: Having descriptive hostnames can aid in network troubleshooting and administration, as it provides clear identification of each system.
  5. Easier System Management: Renaming the hostname can simplify system management tasks, such as remote administration, system monitoring, and log analysis.

Prerequisites

1) Make sure to log in as root or the user with sudo privileges.

Step 1 - Display the Current Hostname

1) There is a tool named  hostnamectl, which is used to change or display the hostname in Debian 11 and other Linux distributions.

2) After that, type hostnamectl without any option to view the current system hostname:

hostnamectl

The output will display the current system hostname. Like, here it is host.vegastack.com:

Output
Static hostname: host.vegastack.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 70a3f06298014fd9ac42e5dc1de1034a
           Boot ID: 1dc8b9af89a4426b99cb348f6d483757
    Virtualization: oracle
  Operating System: Debian GNU/Linux 10 (buster)
            Kernel: Linux 4.19.0-5-amd64
      Architecture: x86-64

Step 2 - Changing the System Hostname

The hostname acts as a label to identify a machine on the network. It is not advisable to set the same hostname on two different machines if they are in the same network. Use a fully qualified domain name (FQDN) as the system hostname.

Follow the below two steps to change the Hostname in Debian 10 Linux:

1. Use the hostnamectl set-hostname command to set the new hostname.

sudo hostnamectl set-hostname xyz.example.com

You won't be getting any output after running the above command, 0 is returned if it is a success, otherwise a non-zero error code will be returned.

2. After that, replace the old hostname and add a new one in /etc/hosts.

127.0.0.1   localhost
127.0.0.1   xyz.example.com xyz # Add this line

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Step 3 - Verifying the Change

1) Use the hostnamectl command to verify if the hostname is changed successfully.

hostnamectl

You will get a hostname printed on the command line.

Output

Static hostname: xyz.example.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 70a3f06298014fd9ac42e5dc1de1034a
           Boot ID: 1dc8b9af89a4426b99cb348f6d483757
    Virtualization: oracle
  Operating System: Debian GNU/Linux 10 (buster)
            Kernel: Linux 4.19.0-5-amd64
      Architecture: x86-64

FAQs to Change Hostname on the Debian 11 Linux

What is the valid hostname?

Valid characters for the hostnames are ASCII(7) letters from a to z. The digits from 0 to 9, as well as the hyphen (-). A hostname will not usually start with a hyphen.

What is a hostname in the URL?

The hostname property of the URL interface is basically a USV-String that mainly contains the domain name of the URL.

How can I check the current hostname on Debian 11? 

To check the current hostname, run the hostname command in the terminal.

Which text editor should I use to modify the hostname file? 

You can use any text editor you are comfortable with, such as nano, vi, or vim. Ensure that you have the necessary permissions to edit system files.

Do I need to reboot the system after changing the hostname? 

Rebooting is not necessary immediately after changing the hostname. However, some services may require a restart or reconfiguration to recognize the new hostname.

How can I change the hostname using the hostnamectl command? 

You can change the hostname using the hostnamectl command by running sudo hostnamectl set-hostname [new_hostname].

What other configuration files may be affected by changing the hostname? 

When changing the hostname, the /etc/hosts file may require modification to ensure that the new hostname is associated with the correct IP address.

Conclusion

By changing the hostname, you benefit from easier system management, enhanced security, consistent organizational conventions, and improved network troubleshooting capabilities.

We hope this detailed tutorial helped you to change the Hostname on Debian 11 Linux.

If you have any queries or doubts, please leave them in the comment below. We'll be happy to address them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.