CentOS7のホスト名変更
CentOS7でホスト名を変更したい場合、/etc/hostnameファイルを変更すれば恒久的にHostnameを変更できますが、
hostnamectlというコマンドがあるので、そのコマンドを利用する方法を記載します。
確認と一時的な変更方法
[root@test]# hostname←現在のホスト名を確認 localhost.localdomain [root@test]# hostname hogehoge.hoge←一時的に変更(再起動すると元に戻ります。) [root@test]# hostname←現在のホスト名を確認 hogehoge.hoge←変更されている
恒久的な変更
再起動しても変更されないように恒久的に変更します。
[root@test]# hostnamectl set-hostname hogehoge.hoge←恒久的に変更 [root@test]# hostnamectl←確認 Static hostname: hogehoge.hoge Icon name: computer Chassis: n/a Machine ID: 3388176caf6243c289f9e1ef7484903b Boot ID: 695b12cfcdae4853a01fb482dcd26c40 Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-229.20.1.el7.x86_64 Architecture: x86_64