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?

Oracle Linuxのホスト名を変更する

0
Posted at

前の記事

構築編

ホスト名変更(2026/05/02インストール時点)

1.ホスト名変更コマンド

1.1.コマンド

hostnamectlコマンドの実行 sudo hostnamectl set-hostname test-server2で変更。
[opc@test-server ~]$ sudo hostnamectl set-hostname test-server2
[opc@test-server ~]$ hostname
test-server2

確認してからの再起動

[opc@test-server ~]$ sudo reboot
[opc@test-server ~]$ hostname
test-server
再起動したら元に戻る!

2.ホスト名設定の確認

2.1.ホスト名設定の確認

oci-hostname.confの初期設定 cat /etc/oci-hostname.confで確認。
[opc@test-server ~]$ cat /etc/oci-hostname.conf
# This configuration file controls the hostname persistence behavior for Oracle Linux
# compute instance on Oracle Cloud Infrastructure (formerly Baremetal Cloud Services)
# Set PRESERVE_HOSTINFO to one of the following values
#   0 -- default behavior to update hostname, /etc/hosts and /etc/resolv.conf to
#        reflect the hostname set during instance creation from the metadata service
#   1 -- preserve user configured hostname across reboots; update /etc/hosts and
#           /etc/resolv.conf from the metadata service
#   2 -- preserve user configured hostname across instance reboots; no custom
#        changes to /etc/hosts and /etc/resolv.conf from the metadata service,
#        but dhclient will still overwrite /etc/resolv.conf
#   3 -- preserve hostname and /etc/hosts entries across instance reboots;
#        update /etc/resolv.conf from instance metadata service
PRESERVE_HOSTINFO=0

設定は

PRESERVE_HOSTINFO=0

ここ!

インストール時点での設定ファイルに戻る設定!

2.2.設定の変更

oci-hostname.confの変更

初期設定は

PRESERVE_HOSTINFO=0

0:リブートすると元に戻る

なので

PRESERVE_HOSTINFO=2

2:リブートしても変更を維持するに変更する。

sudo vi /etc/oci-hostname.confで変更。

[opc@test-server ~]$ sudo vi /etc/oci-hostname.conf
# This configuration file controls the hostname persistence behavior for Oracle Linux
# compute instance on Oracle Cloud Infrastructure (formerly Baremetal Cloud Services)
# Set PRESERVE_HOSTINFO to one of the following values
#   0 -- default behavior to update hostname, /etc/hosts and /etc/resolv.conf to
#        reflect the hostname set during instance creation from the metadata service
#   1 -- preserve user configured hostname across reboots; update /etc/hosts and
#           /etc/resolv.conf from the metadata service
#   2 -- preserve user configured hostname across instance reboots; no custom
#        changes to /etc/hosts and /etc/resolv.conf from the metadata service,
#        but dhclient will still overwrite /etc/resolv.conf
#   3 -- preserve hostname and /etc/hosts entries across instance reboots;
#        update /etc/resolv.conf from instance metadata service
PRESERVE_HOSTINFO=2
設定変更後にホスト名の変更 sudo hostnamectl set-hostname test-server2で変更。
[opc@test-server ~]$ sudo hostnamectl set-hostname test-server2
[opc@test-server ~]$ hostname
test-server2

確認してからの再起動

[opc@test-server ~]$ sudo reboot
[opc@test-server2 ~]$ hostname
test-server2
再起動してもOK!

最後に

記事の内容はCC BY-SA 4.0(著作者の情報とCCライセンス継承はお願いします。商用利用・改変・再配布は問題なし)です。

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?