How to Change Hostname on Debian 9 Linux

A quick tutorial for the steps required to change the hostname on your Debian 9 system.

The hostname is set at the time when the Debian operating system is installed or if you are spinning up a virtual machine it is dynamically assigned to the instance at startup.

The method described in this tutorial will work without the need of restarting your Linux system.


Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges.

Display the Current Hostname:

Copy to Clipboard1


Change the Hostname:

Step 1. Change the hostname

Copy to Clipboard1

sudo hostnamectl set-hostname

Step 2. Edit the hosts file:

Copy to Clipboard1

sudo nano /etc/hosts

The file should look similar to this one:Copy to Clipboard1 localhost 
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


More Posts

Share on facebook
Share on twitter
Share on linkedin

Sign up for our newsletters


Book Now Free SEO Consultation


Take your ecommerce site to next the level


Website Development