hostnamectl

Query or change the system hostname

Supplementary instructions

hostnamectl can be used to query and change the system hostname and related settings.

grammar

hostnamectl [options...] directive...

Commands

status displays the current hostname settings
set-hostname NAME Set the system host name
set-icon-name NAME sets the icon name of the host
set-chassis NAME sets the chassis type of the host
set-deployment NAME sets the deployment environment of the host
set-location NAME sets the host location

Options

-h --help show this help
     --version Show package version
     --no-ask-password Do not prompt for password
-H --host=[USER@]HOST operates on the remote host
-M --machine=CONTAINER Perform operations on local containers. Specify the container name to connect to.
--transient, --static, --pretty
                         If status is called (or no explicit command is given) and one of these switches is specified, hostnamectl will print out only this selected hostname.

Example

Show hostname settings

$ hostnamectl status

Change the host name (permanent modification, no need to restart~)

$ sudo hostnamectl set-hostname newname