CentOS 7 - ホスト名変更

■一時的に変更

# 変更
[root@localhost ~]# hostname test-server

# 確認
[root@localhost ~]# hostname
test-server

 

■恒久的に変更

# 変更
[root@localhost ~]# hostnamectl set-hostname testsrv

# 確認
[root@localhost ~]# hostnamectl
   Static hostname: testsrv
         Icon name: computer-desktop
           Chassis: desktop
        Machine ID: ********************************
           Boot ID: ********************************
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-327.el7.x86_64
      Architecture: x86-64
      
# 設定ファイルはCentOS6(/etc/sysconfig/network)と異なる
[root@localhost ~]# cat /etc/hostname
testsrv

 

■参考
CentOS 7 : ホスト名を設定する
CentOS 7 の Hostname を変更する