Polecenia Linuksa

How to Set Hostname Using Hostnamectl Command?

How to Set Hostname Using Hostnamectl Command?
The hostname is an identity of the system and is used by the networks to search the system.

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:

  1. Static Hostname: Set by system administrators
  2. Dynamic Hostname: Set by mDNS servers on execution time
  3. Pretty Hostname: Set by system administrators or user

The syntax of the “hostnamectl” command is given below:

hostnamectl [options… ] [command… ]

How to Use “hostnamectl” Command:

Execute the “hostnamectl” command without giving any argument in the terminal to display the current status of hostname:

$ hostnamectl

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:

$ hostnamectl set-hostname [set static-hostname] -static

Suppose, to set hostname as “Linux-User”, the command would be:

$ hostnamectl set-hostname Linux-User --static

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:

$ hostnamectl set-hostname [“set pretty-hostname”] -pretty

For instance, to assign a pretty hostname as “Linux”, execute the command:

$ hostname set-hostname “Linux” --pretty

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 set-hostname “Linux” --pretty
$ hostnamectl --pretty status

To display the help of the “hostnamectl” command in terminal, type:

$ hostnamectl --help

To display the version of the “hostnamectl” command, run:

$ hostname --version

Conclusion:

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.

WinMouse lets you customize & improve mouse pointer movement on Windows PC
If you want to improve the default functions of your mouse pointer use freeware WinMouse. It adds more features to help you get the most out of your h...
Mouse left-click button not working on Windows 10
If you are using a dedicated mouse with your laptop, or desktop computer but the mouse left-click button is not working on Windows 10/8/7 for some rea...
Cursor jumps or moves randomly while typing in Windows 10
If you find that your mouse cursor jumps or moves on its own, automatically, randomly while typing in Windows laptop or computer, then some of these s...