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-
- First, let us configure a Static hostname-
- Execute the following command to display the system’s hostname-
$ hostname - You can also temporarily use the hostname command to modify the system’s name. Here is an example:
$ hostname demo.example1.com - The change is temporary. Once you reboot, the changes will revert.
- Execute the following command to display the system’s hostname-
- Now, let us configure a persistent hostname-
- 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”.
- Let us take an example of changing the hostname permanently using the hostnamectl command. This shows the change:
$ hostnamectl set-hostname server1.example1.com - Do not miss out to verify the change using the hostname command after executing the command.
- 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.