注册阿里云服务器后主机名称太长看着不舒服所以想改名

在网上找了好几种方法,大多就是更改/etc/network和/etc/hosts文件然后进行重启,试了几次都没有改过了

然后在博客https://blog.csdn.net/weixin_37282478/article/details/82965461,找到了很好的方法

hostnamectl set-hostname ''liangkk

关于hostnamectl命令简单介绍

1、hostnamectl --help

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               

2、hostnamectl 或者hostnamectl status

   Static hostname(主机名称): liangkk
         Icon name(图标名称): computer-vm
           Chassis(底盘类型): vm
         Machine ID(机器ID): 963c2c41b0833f7b063dddac6b2e486
            Boot ID(引导ID): 83dee24a02896b5a73986b1913f61f7
     Virtualization(虚拟化): kvm
 Operating System(操作系统): CentOS Linux 7 (Core)
      CPE OS Name(操作系统): cpe:/o:centos:centos:7
               Kernel(内核): Linux 3.10.0-514.26.2.el7.x86_64
         Architecture(架构): x86-64