Site icon AWS: © LimitlessV, Software Development Solutions.

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.

Prerequisites:

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

Display the Current Hostname:

Copy to Clipboard1

hostnamectl

Change the Hostname:

Step 1. Change the hostname

Copy to Clipboard1

sudo hostnamectl set-hostname new-host-name.example.com

Step 2. Edit the hosts file:

Copy to Clipboard1

sudo nano /etc/hosts

The file should look similar to this one:Copy to Clipboard1

127.0.0.1 localhost
127.0.0.1 new-host-name.example.com 
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Exit mobile version