Query or change the system hostname
hostnamectl can be used to query and change the system hostname and related settings.
hostnamectl [options...] directive...
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
-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.
Show hostname settings
$ hostnamectl status
Change the host name (permanent modification, no need to restart~)
$ sudo hostnamectl set-hostname newname