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 groups Command: Show a User's Group Memberships

Linux groups Command: Show a User's Group Memberships

Learn how to show a User's Group Memberships with the Linux groups command, including practical examples, key options, and important precautions.

Linux sed Command: Search and Replace Text Streams

Linux sed Command: Search and Replace Text Streams

Learn how to search and Replace Text Streams with the Linux sed command, including practical examples, key options, and important precautions.

Linux watch Command: Run a Command Repeatedly

Linux watch Command: Run a Command Repeatedly

Learn how to use the Linux watch command to rerun a command at regular intervals and highlight changing output, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux htop Command: Explore Processes Interactively

Linux htop Command: Explore Processes Interactively

Learn how to explore Processes Interactively with the Linux htop command, including practical examples, key options, and important precautions.

Linux umount Command: Unmount a Filesystem Safely

Linux umount Command: Unmount a Filesystem Safely

Learn how to unmount a Filesystem Safely with the Linux umount command, including practical examples, key options, and important precautions.

Linux find Command: Search Files by Name, Type, Size, and Time

Linux find Command: Search Files by Name, Type, Size, and Time

Learn how to search with Linux find by name, file type, size, and modification time, combine expressions, run commands safely, and verify targets before deletion.

Linux Tutorial / File System Basics: Paths and Key Directories

Linux Tutorial / File System Basics: Paths and Key Directories

Understand the Linux directory tree, read absolute and relative paths, and learn what common directories such as /home, /etc, and /var are used for.

Linux whoami Command: Show the Effective User Name

Linux whoami Command: Show the Effective User Name

Learn how to show the Effective User Name with the Linux whoami command, including practical examples, key options, and important precautions.

Linux Administration Memo: Essential Commands and System Checks

Linux Administration Memo: Essential Commands and System Checks

A compact Linux administration reference for checking system information, processes, storage, networking, users, permissions, services, and logs.

Linux xz Command: Compress a File in xz Format

Linux xz Command: Compress a File in xz Format

Learn how to compress a File in xz Format with the Linux xz command, including practical examples, key options, and important precautions.