The “hostnamectl” is a Linux command that is used to set the hostname in the terminal without even opening and editing in the etc/hostname file of a system.
Using the “hostnamectl” command, the user can edit the static, pretty, and transient hostname as well.
This command-line utility is categorized into three (3) types:
- Static Hostname: Set by system administrators
- Dynamic Hostname: Set by mDNS servers on execution time
- Pretty Hostname: Set by system administrators or user
The syntax of the “hostnamectl” command is given below:
How to Use “hostnamectl” Command:
Execute the “hostnamectl” command without giving any argument in the terminal to display the current status of hostname:
Change Static Hostname:
The “hostnamectl” command allows the user to change the “static hostname” without even restarting the system.
Run the following command syntax in terminal and set the “static hostname” according to your need:
Suppose, to set hostname as “Linux-User”, the command would be:
The changed static hostname is visible in the terminal.
The “pretty hostname” can also be changed through the “–pretty” option of the “hostnamectl” command. So, type in double quotes (“”) the name that you want to set and execute it in terminal:
For instance, to assign a pretty hostname as “Linux”, execute the command:
It can be seen in the above image that the pretty hostname has changed.
To check if the “pretty-hostname” is updated on the system or not, first, set the name you want to change, then execute the “–pretty status” command to confirm the modification:
$ hostnamectl --pretty status
To display the help of the “hostnamectl” command in terminal, type:
To display the version of the “hostnamectl” command, run:
The “hostnamectl” command is a handy command to modify the system’s hostname without changing the etc/hostname file. In this guide, we have learned that how to set static and pretty hostname of a system.