- 修改vi /etc/hosts
127.0.0.1 Server_China localhost.localdomain localhost - 修改vi /etc/sysconfig/network
HOSTNAME=Server_China - 输入下面命令生效
#hostname Server_China - centos7 设置主机名
#!/bin/bash if [ $# -ne 1 ]; then echo `basename $0` "input hostname" else hostnamectl --static set-hostname $1 hostnamectl --transient set-hostname $1 fi