Skip to content

Change hostname

Updating the Hostname on Debian 12

About this guide

This guide outlines how to change the hostname on a Debian 12 system using the terminal.


1. Set the New Hostname

Run the following command to set a new hostname:

sudo hostnamectl set-hostname <new-hostname>

Replace <new-hostname> with your desired hostname.


2. Update /etc/hosts

Open the /etc/hosts file to reflect the new hostname:

sudo vim /etc/hosts

Ensure the line referencing 127.0.1.1 is updated, for example:

127.0.1.1    your-new-hostname

Why update /etc/hosts?

This ensures proper hostname resolution for local services and prevents potential issues with networking or sudo.


3. Verify the Change

Confirm the hostname was successfully changed:

hostnamectl

Expected output will include:

Static hostname: your-new-hostname

A reboot is not required, but you may log out and back in to see the hostname updated in your shell prompt.