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`.

What is the hostnamectl command?

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.

More in This Category
Linux rmdir Command: Remove Empty Directories

Linux rmdir Command: Remove Empty Directories

Learn how to remove empty directories with Linux rmdir, delete empty parent paths, diagnose failures, and understand when rm -r is different.

Linux scp Command: Copy Files over SSH

Linux scp Command: Copy Files over SSH

Learn how to copy Files over SSH with the Linux scp command, including practical examples, key options, and important precautions.

Linux printf Command: Print Values with a Defined Format

Linux printf Command: Print Values with a Defined Format

Learn how to print Values with a Defined Format with the Linux printf command, including practical examples, key options, and important precautions.

Linux hostnamectl Command: Show and Change the Host Name

Linux hostnamectl Command: Show and Change the Host Name

Learn how to show and Change the Host Name with the Linux hostnamectl command, including practical examples, key options, and important precautions.

Linux rsync Command: Synchronize Files and Directories

Linux rsync Command: Synchronize Files and Directories

Learn how to synchronize Files and Directories with the Linux rsync command, including practical examples, key options, and important precautions.

Linux nohup Command: Keep a Command Running After Logout

Linux nohup Command: Keep a Command Running After Logout

Learn how to use the Linux nohup command to keep a command running after the terminal closes or the user logs out, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux apropos Command: Search Commands by Description

Linux apropos Command: Search Commands by Description

Learn how to use the Linux apropos command to find relevant manual pages by searching description keywords, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux zypper Command: Manage Packages on openSUSE and SUSE

Linux zypper Command: Manage Packages on openSUSE and SUSE

Learn how to manage Packages on openSUSE and SUSE with the Linux zypper command, including practical examples, key options, and important precautions.

Linux mv Command: Move and Rename Files and Directories

Linux mv Command: Move and Rename Files and Directories

Learn how to move and rename files or directories with Linux mv, avoid unwanted overwrites, clarify destination paths, and handle cross-filesystem moves.

Linux top Command: Monitor Processes in Real Time

Linux top Command: Monitor Processes in Real Time

Learn how to monitor Processes in Real Time with the Linux top command, including practical examples, key options, and important precautions.