How to set up a Linux Static and Persistent Hostname

August 21, 2024 / How-to Guide

This post helps in learning how to set up a persistent and static hostname on Linux. In Linux, a static hostname is a set name for your computer that you may use to identify it on a network, but a persistent hostname makes sure the static hostname doesn’t change even when your computer restarts.

Let us follow the steps:

  1. Configure a static hostname:
    1. Type the following command to see the hostname of the system:
      $ hostname
    2. You can also change the system name temporarily by using the hostname command. Here is an illustration:
      $ hostname example1.example
    3. This is a momentary modification. The modifications will be undone when you reboot.
  2. Configure a persistent hostname:
    1. You can directly modify the configuration file at “/etc/hostname” or use the “hostnamectl” command to make a permanent change to the hostname.
    2. Use the “hostnamectl” command to alter the hostname permanently as an example. This proves the change:
      Set-hostname server1.example1.com $ hostnamectl
    3. After running the command, make sure you use the hostname command to confirm the modification.
    4. You may verify the item by displaying the contents of the /etc/hostname file.

You are now familiar with how to configure a static and persistent hostname on Linux. If you face any difficulty, feel free to seek assistance from our support team.