LoginSignup
1
1

More than 5 years have passed since last update.

CentOS 7でhostnameを変更する

Last updated at Posted at 2016-09-16

hostnamectlを使います

デフォルトのhostnameである「localhost.localdomain」から、「local.domain-server.com(任意)」に変更するため、hostnamectlコマンドを使います。

変更前

$ hostname
localhost.localdomain

hostnamectlで変更する

$ hostnamectl set-hostname local.domain-server.com

※CentOS7インストール時にサーバソフトウェアを入れていると、以下のメッセージが出るので、sudoで実行します。

Could not set property: Interactive authentication required.

→権限がないので、sudoで実行。
$ sudo hostnamectl set-hostname local.domain-server.com

※ CentOS 7がminimalだと、以下のようなメッセージが出ます。

==== AUTHENTICATING FOR org.freedesktop.hostname1.set-static-hostname ===
Authentication is required to set the statically configured local host name, as well as the pretty host name.
Authenticating as: user01
Password: 
==== AUTHENTICATION COMPLETE ===

→Passwordプロンプトでパスワードを入力しEnterを押します。

変更後

$ hostname
local.domain-server.com

簡単ですね。

他にも、nmtuiや、nmcliで変更できますが、全部、/etc/hostnameを変更しているので、直接ファイルを編集しても同じことができます。

※ログイン中のプロンプトのホスト名は、一旦ログアウトしてログインし直さないと反映されません。

1
1
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
1
1