Forrest logo
back to the hostnamectl tool

hostnamectl:tldr:d05c4

hostnamectl: Get the hostname of the computer.
$ hostnamectl
try on your machine

The hostnamectl command is used to query or modify the system's hostname on a Linux operating system. It is commonly used in distributions that utilize the systemd init system, such as Ubuntu, Fedora, and CentOS.

When used without any arguments, hostnamectl displays the current status and configuration of the system's hostname, along with its related properties. This includes the static hostname (the hostname that is set at boot time and persistent across reboots), the transient hostname (the transient name set by DHCP or mDNS), and the chassis type.

To modify the hostname, you can use the hostnamectl command with some additional options. For example:

  • hostnamectl set-hostname [NEW_HOSTNAME]: This command allows you to set a new hostname for your system. Replace [NEW_HOSTNAME] with the desired hostname.
  • hostnamectl set-hostname --pretty "[PRETTY_HOSTNAME]": This command sets a pretty hostname, which is a more human-readable form of the hostname. Replace [PRETTY_HOSTNAME] with the desired pretty hostname.
  • hostnamectl set-chassis [CHASSIS_TYPE]: This command sets the system's chassis type, which can be one of the options like "desktop", "laptop", "server", etc. Replace [CHASSIS_TYPE] with the desired chassis type.

Note that using hostnamectl to modify the hostname typically requires root or sudo privileges. After modifying the hostname, it is recommended to reboot the system for the changes to take effect completely.

Overall, hostnamectl provides a convenient way to manage and configure the hostname of a Linux system using systemd.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the hostnamectl tool