CentOS8永久修改主机名

  • 系统:腾讯云CentOS 8.2

1. 修改主机名

  • 查看主机名
[root@VM-0-16-centos ~]# hostname
VM-0-16-centos
  • 修改主机名为 zifeng
[root@VM-0-16-centos ~]# hostnamectl set-hostname zifeng
[root@VM-0-16-centos ~]# hostname
zifeng

2. 修改hosts文件

  • 修改 /etc/hosts 文件,使IP映射到新的主机名
[root@VM-0-16-centos ~]# cat /etc/hosts
127.0.0.1 VM-0-16-centos VM-0-16-centos
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4

::1 VM-0-16-centos VM-0-16-centos
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
[root@VM-0-16-centos ~]# vim /etc/hosts 
[root@VM-0-16-centos ~]# cat /etc/hosts
127.0.0.1 zifeng
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4

::1 zifeng
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

3. 重启电脑

  • 重启电脑,立即生效
[root@VM-0-16-centos ~]# reboot

[root@zifeng ~]# hostnamectl status
   Static hostname: zifeng
         Icon name: computer-vm
           Chassis: vm
        Machine ID: ...
           Boot ID: ...
    Virtualization: kvm
  Operating System: CentOS Linux 8 (Core)
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-193.6.3.el8_2.x86_64
      Architecture: x86-64

你可能感兴趣的:(Linux,linux,centos)