LinuxCommandLibrary

hostnamectl

Control or change the system's hostname

TLDR

Get the hostname of the computer

$ hostnamectl
copy

Set the hostname of the computer
$ sudo hostnamectl set-hostname "[hostname]"
copy

Set a pretty hostname for the computer
$ sudo hostnamectl set-hostname --static "[hostname.example.com]" && sudo hostnamectl set-hostname --pretty "[hostname]"
copy

Reset hostname to its default value
$ sudo hostnamectl set-hostname --pretty ""
copy

SYNOPSIS

hostnamectl [OPTIONS...] {COMMAND}

PARAMETERS

status [PROPERTY...]
    Print current hostname, machine ID, chassis, and related info.

set-hostname NAME
    Set system hostname; combine with --static, --transient, or --pretty.

set-icon-name NAME
    Set icon name (e.g., 'computer-laptop') for machine identification.

set-chassis TYPE
    Set chassis type: laptop, desktop, server, tablet, etc.

set-deployment NAME
    Set deployment name (e.g., 'phatbook').

set-location LOCATION
    Set physical location description.

reboot [PARAMETER]
    Schedule system reboot.

poweroff [PARAMETER]
    Schedule system power off.

suspend [PARAMETER]
    Schedule suspend to RAM.

hibernate [PARAMETER]
    Schedule hibernation.

-h, --help
    Print help and exit.

-V, --version
    Print version information.

--static
    Show/set static (persistent) hostname.

--transient
    Show/set transient (temporary) hostname.

--pretty
    Show/set pretty (display) hostname.

--line
    Truncate lines to fit screen (status).

-P, --property=NAME
    Show only specified property.

-a, --all
    Show all properties, including empty.

-l, --legend=no
    Do not show legend (status).

--mark-changed
    Notify services of hostname change.

DESCRIPTION

hostnamectl is a systemd utility for querying and setting system identification data, including hostnames, machine ID, chassis type, deployment environment, location, and icon name. It supports three hostname types: static (persistent, from /etc/hostname), transient (temporary, e.g., from DHCP), and pretty (user-friendly display name).

The status command displays current settings, optionally filtered by type or property. Use set-hostname and variants to modify values, specifying --static, --transient, or --pretty. Other set-* commands update specific attributes like chassis (e.g., 'laptop', 'server') or icon (e.g., 'computer-laptop'). Power commands (reboot, poweroff, suspend, hibernate) schedule system state changes via logind.

It interacts with systemd-hostnamed.service over D-Bus. Changes require privileges (root or polkit) and may trigger hostnamectl --mark-changed for notifications. Primarily for desktop/server management, ensuring consistent identity across local and remote access.

CAVEATS

Requires systemd-based system. Setting properties needs root or polkit auth. Hostname changes may not update kernel hostname immediately or affect all network services. Power commands require logind privileges.

HOSTNAME TYPES

Static: Boot-persistent (/etc/hostname).
Transient: Runtime/DHCP-set.
Pretty: Cosmetic, multi-word allowed.

EXAMPLES

hostnamectl status
hostnamectl set-hostname example.com --static
hostnamectl set-chassis laptop
hostnamectl reboot

STATUS PROPERTIES

IconName, Chassis, MachineID, StaticHostname, TransientHostname, PrettyHostname, etc.

HISTORY

Introduced in systemd 197 (March 2013) as part of hostnamed integration. Evolved with systemd releases to support more properties and power management.

SEE ALSO

hostname(1), loginctl(1), systemctl(1), systemd-hostnamed.service(8), machine-info(5)

Copied to clipboard