How to Change Hostname on Debian 10

Change Hostname on Debian 10

In this article, we will have explained the necessary steps to change hostname on Debian 10. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Hostname is a command to display the DNS name of a server or NIS domain name. It is a name that is given to a computer that attached to the network that uniquely identifies over a network and thus allows it to be accessed without using its IP address. The hostname will be set when you are installing the operating system and for virtual machines, it is dynamically assigned when instance created. By using hostname a network differentiates between two systems so it is important to have a different hostname for each machine in the same network.

Change Hostname on Debian

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo apt update
sudo apt upgrade

Step 2. Change the hostname on Debian 10.

Run below command to check the hostname for your system:

$ hostnamectl
   
   Static hostname: linuxtips
         Icon name: computer-netbook
           Chassis: laptop
        Machine ID: 2381eintanramonae781c843f399507ea2
           Boot ID: 2902f9a594944fe28meilana229ef0
  Operating System: Debian GNU/Linux 10 (buster)
            Kernel: Linux 4.18.0-46-generic
      Architecture: x86-64

Here you can change the hostname of the system editing /etc/hosts file:

sudo nano /etc/hostname
127.0.0.1	localhost
192.168.77.20   debian.linuxtips.us

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Now to verify the change run below command:

hostnamectl

The hostnamectl tool will use SSH to connect to the remote system. One can see help page by typing:

hostnamectl --help

Congratulation, you have learned how to change hostname on Debian 10 Buster. If you have any question, please leave a comment below.