前の記事
構築編
ホスト名変更(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
最後に
記事の内容はCC BY-SA 4.0(著作者の情報とCCライセンス継承はお願いします。商用利用・改変・再配布は問題なし)です。