How to permanently change the hostname on Debian Linux 12, 11 or 10

11.07.2023 Author:

How to permanently change the hostname on Debian Linux 12, 11 or 10 using hostnamectl, update /etc/hosts and verify the new system name.

You can use hostnamectl or hostname to display or set the hostname of a Debian Linux system. This tutorial explains how to change it permanently.

Follow these steps:

  1. Connect to your server over SSH: ssh user@server-name.
  2. Become root using sudo -s or su -.
  3. To set the hostname to server1, run: hostnamectl set-hostname server1.
  4. Edit /etc/hosts and update the hostname entries: vi /etc/hosts. You can use another text editor if you prefer.
  5. Verify the change by running hostnamectl again.

After completing these steps, the system’s hostname should be server1.

About the author

Leszek Iwaniec is the owner of Projectic. He works on online store implementations, custom applications and technical support. On the blog, he describes problems and solutions involving PrestaShop, Laravel and system integrations, drawing on the team’s project experience.

Back