Skip to content

Instantly share code, notes, and snippets.

@zhaopan
Last active March 1, 2023 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhaopan/5b50870edf1ed7f50f4e4a73277c0cec to your computer and use it in GitHub Desktop.
Save zhaopan/5b50870edf1ed7f50f4e4a73277c0cec to your computer and use it in GitHub Desktop.
# 设置主机名称 (centos7+支持)
# centos6修改主机名的配置文件是 /etc/sysconfig/network
# centos7修改主机名的配置文件是 /etc/hostname
$hostnamectl set-hostname <your hostname>
--static # 注:该命令会同步修改 /etc/hostname
--pretty # 给主机起别名(昵称)
# eg: 设置为 ts01
$hostnamectl set-hostname "ts01" --static
# 查看设置后的主机信息
$hostnamectl
>
Static hostname: ts01
Icon name: computer-vm
Chassis: vm
Machine ID: <MachineID>
Boot ID: <BootID>
Virtualization: kvm
Operating System: CentOS Stream 9
CPE OS Name: cpe:/o:centos:centos:9
Kernel: Linux 5.14.0-202.el9.x86_64
Architecture: x86-64
Hardware Vendor: Aliyun Cloud
Hardware Model: CVM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment