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.

Gry Jak wyświetlić nakładkę OSD w pełnoekranowych aplikacjach i grach dla systemu Linux?
Jak wyświetlić nakładkę OSD w pełnoekranowych aplikacjach i grach dla systemu Linux?
Granie w gry pełnoekranowe lub korzystanie z aplikacji w trybie pełnoekranowym bez rozpraszania uwagi może odciąć Cię od istotnych informacji systemow...
Gry 5 najlepszych kart do przechwytywania gier
5 najlepszych kart do przechwytywania gier
Wszyscy widzieliśmy i uwielbialiśmy strumieniowe rozgrywki na YouTube on. PewDiePie, Jakesepticye i Markiplier to tylko niektórzy z najlepszych graczy...
Gry Jak stworzyć grę na Linuksie
Jak stworzyć grę na Linuksie
Dziesięć lat temu niewielu użytkowników Linuksa przewidywało, że ich ulubiony system operacyjny pewnego dnia stanie się popularną platformą do gier dl...