Linux hostのstatic hostnameとしてnode1をboot時に読み込ませる。
標準的なsystemd系構成の主fileを選ぶ。
適切なfileはどれか。
/etc/hostnameはstatic hostnameを通常1行で保持する。/etc/hostsの名前対応とは別に管理する。
詳細解説
/etc/hostsIP addressとhost nameのlocal対応を記述するfileでstatic hostname本体ではない。
誤り。/etc/hostsに自hostのmappingを置くことはあるが、kernelへboot時のstatic hostnameを設定する主fileではない。
/etc/hostnamestatic hostnameを保持する標準的なfileである。
正しい。/etc/hostnameへstatic nameを保持し、boot時やhostnamedが読み込む。
/etc/resolv.confDNS resolverのnameserverやsearch listを設定する。
誤り。resolv.confはnameserver、search、options等をresolverへ指示する。
/etc/nsswitch.conf名前解決等のdatabase検索順を設定する。
誤り。nsswitch.confはhosts: files dns等の検索service順を定め、hostname値自体を保存しない。
実際に確かめる
一時的な検証環境で実行できる例です。
printf '%s
' '/etc/hostname -> static hostname'期待される結果
/etc/hostname -> static hostname理解のポイント
- /etc/hostname
- 1行のstatic name
- /etc/hostsとは別
確認時の注意
- 確認環境: file役割対応表の表示のみ
基礎のおさらい
短い名前とFQDN
distributionや運用policyにより短いhostnameまたはFQDNを格納する。DNS・/etc/hostsとの整合も取る。
管理tool
hostnamectlを使うとruntimeと永続fileの更新をsystemd-hostnamed経由でまとめて行える。