Centos 更改主机名

Centos 6.x

[root@localhost ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=192.168.10.1

[root@localhost ~]# vi /etc/hosts
127.0.0.1       localhost localhost.localdomain server

Centos 7.x

[root@localhost log]# hostnamectl status
   Static hostname: localhost.yvsy7
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 68a9a20de8ab4776a88eff33bd41b8ae
           Boot ID: 405ba16753364bad82f4d057a51b6499
    Virtualization: microsoft
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-123.el7.x86_64
      Architecture: x86_64
[root@localhost ~]# hostnamectl --static  #静态
localhost.localdomain
[root@localhost ~]# hostnamectl --transient #瞬态
localhost.localdomain
[root@localhost ~]# hostnamectl --pretty  #灵活
[root@localhost ~]# hostnamectl set-hostname server #同时修改三种状态主机名
[root@localhost ~]# vim /etc/hosts
127.0.0.1       localhost localhost.localdomain server
[root@localhost ~]# hostnamectl --static set-hostname server #永久修改主机名
  1. ducky512 2015.06.17 9:02am

    我就是随便看看

HTML tag cannot be used in this comment.