How To Change Your Hostname on Debian

How To Change Your Hostname on Debian

In this tutorial, we will show you how to change your hostname on a Debian operating system. Changing the hostname of your Debian server is a very easy task and if you carefully follow the instructions provided in this tutorial it will take you no longer than 5 minutes to do it.

What is a hostname?

The hostname is a label that is assigned during the initial server setup and it is used to identify and easily distinguish one server from another. When choosing your hostname you should also make sure to use a Fully Qualified Domain Name (FQDN) and it should be pointed to your server IP address so you can access your server by using it.

Connect to your server

Before you change your hostname, you will first need to connect to your Debian server via SSH.

Once you have successfully connected to your server, you can use the following command to check your current hostname:

hostname

And to check your Fully Qualified Domain name (FQDN) you can run the following command instead:

hostname -f

Change your hostname

To change your hostname, we can simply run the following command:

hostname new.hostname.com

Make sure you replace “new.hostname.com” with the hostname you would like to use. This will change your hostname but only until next server reboot.

On Debian based systems, the hostname of the system is stored in the /etc/hostname file. Upon server boot, the hostname contained in this file is assigned to the system by the init script located at /etc/init.d/hostname.sh.

So in order to change our hostname permanently, you will need to update this file. You can open it with your favorite text editor, for example:

nano /etc/hostname

Change the hostname, save the file and exit the text editor.

You can now execute the init script in order to make the change active immediately:

/etc/init.d/hostname.sh start

This will also permanently update our hostname even after a server reboot.

Change hostname with hostnamectl command

Another alternative way to change your hostname is to use the hostnamectl command. You can run the following command in order to permanently update the hostname of your system:

hostnamectl set-hostname new.hostname.com

You can also check the current hostname status with:

hostnamectl status

You should get an output similar to this:

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

For more information 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

Commands:
 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

 

If you use one of our Linux Support Services, you don’t have to change your hostname yourself, you can simply ask our expert Linux admins to change the hostname on your Debian VPS for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on How To Change Your Hostname on Debian, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *