Skip to main content
Engineering LibreTexts

08-C.8.2: Managing Linux Services - hostnamectl

  • Page ID
    35225
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The hostnamectl Command 

    hostnamectl command provides a proper API used to control Linux system hostname and change its related settings. The command also helps to change the hostname without actually locating and editing the /etc/hostname file on a given system.

    Syntax:

    hostnamectl [ OPTIONS ] COMMAND ....

    Where COMMAND can be any of the following:

    • status: Used to check current hostname settings.
    • set-hostname NAME: Used to set system hostname.
    • set-icon-name NAME: Used to set icon name for host.
    • set-chassis NAME: Set chassis type for host.

    Types of hostname:

    • Static: Assigned by system admin and it is used to initialize the kernel hostname during boot time.
    • Dynamic or Transient: Assigned by mDNS server or DHCP server during run time.
    • Pretty: A high-level hostname assigned by system admin or end-user.

    Command Options:

    Option Meaning
    --no-ask-password Do not query the user for authentication for privileged operations.
    -H, --host= Execute the operation remotely. Specify a hostname, or a username and hostname separated by "@", to connect to. The hostname may optionally be suffixed by a port ssh is listening on, separated by ":", and then a container name, separated by "/", which connects directly to a specific container on the specified host.
    -M, --machine= Execute operation on a local container. Specify a container name to connect to, optionally prefixed by a user name to connect as and a separating "@" character. If the special string ".host" is used in place of the container name, a connection to the local system is made

     

     

    Adapted from:
    "hostnamectl command in Linux with Examples" by Suraj1994, Geeks for Geeks is licensed under CC BY-SA 4.0


    08-C.8.2: Managing Linux Services - hostnamectl is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?