Linux hostnamectl Command: Show and Change the Host Name

`hostnamectl` shows the host name and information about the OS, kernel, and architecture on systemd-based systems. You can also change the host name using `set-hostname`.

The static host name is the permanent name set by the administrator, and the transient name is the name applied to the running system. In the default status output, notice the difference between the two. Changing it does not automatically modify DNS records on other systems or entries in `/etc/hosts`.

Basic syntax

hostnamectl [command] [argument]

Available implementations and options may vary depending on the distribution. Check the current system's description with `man hostnamectl`.

Examples

Current name and system information

First, check the currently visible items such as name, distribution, kernel, etc.

hostnamectl status

Check only the static name

Briefly output the permanent host name needed for scripts or inspections.

hostnamectl --static

Change Hostname

After confirming that it is the correct target, specify the name. Authorization is required as this is a change operation.

sudo hostnamectl set-hostname web01.example.test

Check the current hostname and the scope of change

hostnamectl shows the static hostname as well as information about the operating system and kernel in a systemd environment. To check just the name, query it as follows.

hostnamectl --static

Example output:

web01.example.test

sudo hostnamectl set-hostname new-name usually produces no output even if successful. Run hostnamectl --static again to verify. Changing the hostname does not automatically update DNS records or /etc/hosts, so if a service depends on name resolution, those settings should also be checked separately.

Main Options and Format

Options/Format Description
status Displays the current hostname and system information.
--static Targets the static hostname.
--transient Targets the temporary hostname.
set-hostname name Sets the hostname.
--pretty Targets a human-readable display name.

Precautions when using

Before changing the actual server's name, check the dependencies of DNS, certificates, monitoring, application settings, and /etc/hosts. After the change, verify with hostnamectl status and the necessary name lookups, and when reverting, run set-hostname again with the previous name. It cannot be used in environments without systemd.

Frequently Asked Questions

If I change the name with hostnamectl, will DNS also change?

No. Changing the hostname on the local system and changing DNS records are separate tasks.

Official Documentation

You can check the exact behavior of the options and implementation differences in the official documentation related to hostnamectl.