Skip to content

How to Change the Hostname in Debian 12 BookWorm

How to Change the Hostname in Debian 12 BookWorm


In the vast realm of networked computers, each device needs a unique identifier—a name that allows it to be distinguishable from the crowd. This unique identifier is known as the “hostname.” Whether you are working in a large corporate network or simply tinkering with a personal Linux box, you might find yourself needing to change this hostname at some point. This comprehensive guide walks you through the process of changing the hostname in Debian 12 BookWorm, one of the latest iterations of the popular Linux distribution Debian.


Before diving into the nitty-gritty, ensure you have the following:

  1. Access to a Terminal: You can access the terminal through your GUI or via SSH if you’re working remotely.
  2. Superuser or sudo Privileges: Administrative access is necessary to make system-wide changes.
  3. Basic Understanding of Linux Command Line: Knowing how to navigate the terminal will be beneficial.
  4. Installed Instance of Debian 12 BookWorm: The instructions are tailored for this specific version.


To make sure we’re on the same page, let’s clarify some terminology:

  1. Hostname: A label assigned to a machine on a network.
  2. Superuser: The administrator with full access to the Linux system.
  3. sudo: Command that allows permitted users to execute a command as a superuser.
  4. /etc/hostname and /etc/hosts: Configuration files storing hostname information.

Backup Current Settings

It’s always prudent to backup important configurations before making any changes. Open the terminal and run:

cp /etc/hostname /etc/hostname.bak cp /etc/hosts /etc/hosts.bak

This creates backup copies of your current hostname and hosts files.

Method 1: Using the hostnamectl Command

Step 1: Check Current Hostname

To see your current hostname, run the following command:


Step 2: Change the Hostname

To change your hostname, execute:

sudo hostnamectl set-hostname new-hostname

Replace new-hostname with your desired hostname. For instance, to change the hostname to “mydebian,” you’d run:

sudo hostnamectl set-hostname mydebian

Step 3: Verify the Changes

Use the hostnamectl command again to check if the hostname has been updated:


Powered by WPeMatico

Go to Source
Author: George Whittaker

Published inUncategorized