0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【RHELでも同様】Linuxでホスト名を変更する【hostnamectlの使い方】

Posted at

あんまりない事かと思いますが、ホスト名の変更って直接/etc/hostnameを編集していますか?
それでも誤りではないのですが、/etc/hostnameを変更してシステムにそれを反映させるために再起動って手間をかけてませんか?
そんな人にお勧めのコマンドがあります。

hostnamectl set-hostname ホスト名

ちなみにホスト名は3種類あります。
上記コマンドを実行すると、これら3個のホスト名全てが更新されます。

static /etc/hostnameに記述されるホスト名
transient カーネルによって保持される一時的なホスト名
pretty 自由形式のホスト名

変更したいホスト名を指定するときは以下のようにします。

hostnamectl set-hostname ホスト名 -- pretty or --static or --transient

ちなみにリモートホストのホスト名を変更する場合は以下のようにします。
この手を使う時はSSHでログインできることが前提となるため注意が必要です。

hostnamectl --host=user@host1.example.com set-hostname ホスト名

上記いずれかの方法でホスト名を変更したら、hostnameコマンドでホスト名が変更されているか確認しましょう。
もしホスト名が変更されていない時は、systemctl restart systemd-hostnamed コマンドを実行して systemd-hostnamed を再起動しシステムに反映させます。

以上、異常に忘れっぽい自分用のメモでした。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?