hostnamectl

Linux · System · reference only

What it does

Shows and changes the host name and other system data, such as the operating system and kernel, through systemd.

Syntax

hostnamectl [opciones] [orden]

Options and parameters

  • status

    Shows the host name, operating system and kernel; it is the default command.

  • set-hostname nombre

    Changes the host name.

  • hostname

    Shows only the host name.

  • --static

    Acts on the static name stored in /etc/hostname.

  • --transient

    Acts on the transient name assigned by the network.

  • --pretty

    Acts on the pretty name, which allows spaces and accents.

  • -H equipo

    Runs the command on a remote host over SSH.

Usage examples

  • hostnamectl

    Shows the host name, operating system and architecture.

  • sudo hostnamectl set-hostname servidor1

    Changes the host name to servidor1 permanently.

  • hostnamectl hostname

    Prints only the current name.

  • hostnamectl --static

    Shows the static name stored in /etc/hostname.

Notes and common mistakes

  • The name change is permanent, but you should also update /etc/hosts if the machine resolves itself locally.

Related commands