![【Linux】ホスト名を変更する方法](https://itechsearchengine.com/wp-content/uploads/2021/05/a0b00becd6c8a5fdd0a47804549ff0d3.png)
ホスト名を確認する
hostname
全ホスト名を確認する
hostnamectl
![](https://itechsearchengine.com/wp-content/uploads/2020/11/image-118.png)
ホスト名を変更する方法は2種類あります。
①コマンド(root権限)でホスト名を設定する。(再起動は不要)
②hostnameファイルを変更する。(再起動が必要)
①コマンドでホスト名を設定する。(再起動は不要)
ホスト名を設定する
hostnamectl set-hostname (ホスト名)
全ホスト名を確認する
hostnamectl
![](https://itechsearchengine.com/wp-content/uploads/2020/11/image-119.png)
②hostnameファイルを変更する。(再起動が必要)
hostnameファイルを確認する
cat /etc/hostname
![](https://itechsearchengine.com/wp-content/uploads/2020/11/image-120.png)
hostnameファイルを編集する
vi /etc/hostname
hostnameファイルを確認する
cat /etc/hostname
ホスト名を確認する
hostname
全ホスト名を確認する
hostnamectl
再起動していない状態だと、hostname実行後、まだホスト名が変わっていないことがわかります。
再起動後、ホスト名が変更されていることを確認しましょう。
![](https://itechsearchengine.com/wp-content/uploads/2020/11/image-121.png)
変更したホスト名を有効にするために再起動する
reboot
ホスト名を確認する
hostname
全ホスト名を確認する
hostnamectl
![](https://itechsearchengine.com/wp-content/uploads/2020/11/image-122.png)