1. Home
  2. Linux
  3. Debian
  4. How To Change Your Hostname on Debian

How To Change Your Hostname on Debian

How To Change Your Hostname on Debian
How To Change Your Hostname on Debian


In this tutorial we will teach you how to change your hostname on a Debian operating system.

Replacing the hostname of your Debian server is simple, it should take about 5 minutes of your time when following the steps below.

What is a hostname?

An hostname is a label which is made during the initial server setup, it is made to help you identify and easily recognize one server from another. Once you choose your hostname, ensure to use a Fully Qualified Domain Name (FQDN) and remember that it has to be pointed to your server’s IP address so you may access your server by using it.

Connect to your server

Before changing your hostname, you must first connect to your Debian server via SSH.

After you have successfully connected to your server, you may use the following command to check your current hostname.


To verify your Fully Qualified Domain name (FQDN), you can execute the below command instead.

hostname -f

Change your hostname

In order to change your hostname, simply execute the following command.

hostname new.hostname.com

Ensure that you change ‘new.hostname.com‘ to the hostname you wish to use, this should change your hostname, however, it will only take effect after the server reboots.

On Debian based systems, the hostname of the system is located in the ‘/etc/hostname file’.Once the server boots, the hostname contained in the file is assigned to the system by the init script stored at ‘/etc/init.d/hostname.sh’.

For your hostname to change permanently, you will have to update this file. You can open it with the text editor of your choice; we will be using the nano text editor.

nano /etc/hostname

Replace the hostname with yours before saving the file and closing the text editor.

Feel free to now run the init script so that your change is made active instantly.

/etc/init.d/hostname.sh start

This should also permanently update your hostname, even after a server reboot.
Change hostname with ‘hostnamectl’ command
There is a different way to change your hostname, this is with the ‘hostnamectf command’.
Execute the command below for your hostname to be permanently changed and updated in your system.

hostnamectl set-hostname new.hostname.com

You may check the current hostname status using the following command.

hostnamectl status

You should receive an output similar to the one below.

Static hostname: new.hostname.com
Icon name: computer-container
Chassis: container
Machine ID: ****
Boot ID: ***
Operating System: Debian GNU/Linux 9 (stretch)
Kernel: Linux 2.6.32-042stab127.2
Architecture: x86-64

If you would like to know more about the ‘hostnamectl’ command use the ‘–help’ flag.

hostnamectl --help
hostnamectl [OPTIONS...] COMMAND ...
Query or change system hostname.
 -h --help Show this help
    --version Show package version
    --no-ask-password Do not prompt for password
 -H --host=[USER@]HOST Operate on remote host
 -M --machine=CONTAINER Operate on local container
    --transient Only set transient hostname
    --static Only set static hostname
    --pretty Only set pretty hostname


 status Show current hostname settings
 set-hostname NAME Set system hostname
 set-icon-name NAME Set icon name for host
 set-chassis NAME Set chassis type for host
 set-deployment NAME Set deployment environment for host
 set-location NAME Set location for host
Updated on December 23, 2018

Was this article helpful?

Related Articles

Leave a Comment

[apsl-login-lite login_text='Please login with a social account']