How to Configure a Static and Persistent Hostname on Linux

August 14, 2023 / Servers, Hosting & Email

This guide helps in understanding how to configure a static and persistent hostname on Linux. Static Hostname on Linux is a fixed name for your computer used for identification within a network, whereas a persistent hostname ensures the static hostname remains the same even after the computer restarts.

Let us find out how to configure a static and persistent hostname-

  1. First, let us configure a Static hostname-
    1. Execute the following command to display the system’s hostname-
      $ hostname
    2. You can also temporarily use the hostname command to modify the system’s name. Here is an example:
      $ hostname demo.example1.com
    3. The change is temporary. Once you reboot, the changes will revert.
  2. Now, let us configure a persistent hostname-
    1. To make a lasting change to the hostname, you can either use the “hostnamectl” command or directly edit the configuration file located at “/etc/hostname”.
    2. Let us take an example of changing the hostname permanently using the hostnamectl command. This shows the change:
      $ hostnamectl set-hostname server1.example1.com
    3. Do not miss out to verify the change using the hostname command after executing the command.
    4. By presenting the /etc/hostname file contents, you can check the entry.

That is it! Hope you liked our article. For any help, do contact our technical support team at your earliest.

Spread the love