Redhat 5
    Redhat6

    1. 1 hostname DB-Server --运行后立即生效(新会话生效),但是在系统重启后会丢失所做的修改
    2. 2 echo DB-Server > /proc/sys/kernel/hostname --运行后立即生效(新会话生效),但是在系统重启后会丢失所做的修改
    3. 3 sysctl kernel.hostname=DB-Server --运行后立即生效(新会话生效),但是在系统重启后会丢失所做的修改
    4. 4: 修改/etc/sysconfig/network下的HOSTNAME变量 --需要重启生效,永久性修改。

    https://www.cnblogs.com/kerrycode/p/3595724.html

    Redhat7
    hostnamectl 永久修改 立即生效 不需要重新启动

    1. [root@liwm ~]# hostnamectl set-hostname riyimei
    2. [root@liwm ~]# bash
    3. [root@riyimei ~]#
    4. [root@riyimei ~]# hostnamectl
    5. Static hostname: riyimei
    6. Icon name: computer-vm
    7. Chassis: vm
    8. Machine ID: a1c014c347ec4c488de145182244a866
    9. Boot ID: 2457355e31dd45b7badc9294f02ef562
    10. Virtualization: vmware
    11. Operating System: CentOS Linux 8 (Core)
    12. CPE OS Name: cpe:/o:centos:centos:8
    13. Kernel: Linux 4.18.0-147.el8.x86_64
    14. Architecture: x86-64
    15. [root@riyimei ~]#