以前改hostname的步骤如下:
CentOS6
#临时生效
hostnamenewname
#想重启后也生效要修改文件
sed -i s#HOSTNAME=.*#HOSTNAME=newname
#g /etc/sysconfig/network
CentOS7
#临时生效
hostnamenewname
#想重启后也生效要修改文件
echonewname
> /etc/hostname
使用hostnamectl命令:
#比hostname命令多的是同时修改了/etc/hostname文件
hostnamectl set-hostnamenewname
hostname
hostname的使用帮助如下:
hostnamectl [OPTIONS...] COMMAND ...
Query or change system hostname.
-h --help Show this help
--version Show package version
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
--transient Only set transient hostname
--static Only set static hostname
--pretty Only set pretty hostname
Commands:
status Show current hostname settings
set-hostname NAME Set system hostname
set-icon-name NAME Set icon name for host
set-chassis NAME Set chassis type for host
set-deployment NAME Set deployment environment for host
set-location NAME Set location for host