Fedora 21 でホスト名を永続的に変更する方法

Fedora 21 でホスト名を永続的に変更する方法

fedora の新しいバージョンでホスト名を変更するには、 コマンドを使用すると聞きましたhostnamectl。さらに、最近、この方法で Arch Linux のホスト名を変更しました (成功しました)。ただし、以下を実行すると、

[root@localhost ~]# hostnamectl set-hostname --static paragon.localdomain
[root@localhost ~]# hostnamectl set-hostname --transient paragon.localdomain
[root@localhost ~]# hostnamectl set-hostname --pretty paragon.localdomain

再起動後、変更は保存されません (保存されるという多くの人が主張しているのに反して)。何が問題なのでしょうか?

  • 本当に手動で編集したくない/etc/hostname

また、これは完全に標準の fedora。コア アプリのインストールにはまだ至っていません。

答え1

ホスト名を設定するコマンドは間違いなく ですhostnamectl

root ~ # hostnamectl set-hostname --static "YOUR-HOSTNAME-HERE"

この機能についてもう少し詳しく説明した追加のソースを以下に示します。ホスト名を正しく設定する - Amazon EC2 上の Fedora 20

さらに次のマニュアルページがありますhostnamectl:

HOSTNAMECTL(1)                    hostnamectl                   HOSTNAMECTL(1)

NAME
       hostnamectl - Control the system hostname

SYNOPSIS
       hostnamectl [OPTIONS...] {COMMAND}

DESCRIPTION
       hostnamectl may be used to query and change the system hostname and
       related settings.

       This tool distinguishes three different hostnames: the high-level
       "pretty" hostname which might include all kinds of special characters
       (e.g. "Lennart's Laptop"), the static hostname which is used to
       initialize the kernel hostname at boot (e.g. "lennarts-laptop"), and
       the transient hostname which is a default received from network
       configuration. If a static hostname is set, and is valid (something
       other than localhost), then the transient hostname is not used.

       Note that the pretty hostname has little restrictions on the characters
       used, while the static and transient hostnames are limited to the
       usually accepted characters of Internet domain names.

       The static hostname is stored in /etc/hostname, see hostname(5) for
       more information. The pretty hostname, chassis type, and icon name are
       stored in /etc/machine-info, see machine-info(5).

       Use systemd-firstboot(1) to initialize the system host name for mounted
       (but not booted) system images.

Fedora 21 には、SELinux が hostnamectl アクセスをブロックするというバグがあります。次のタイトルで見つかりました:バグ 1133368 - SELinux が systemd-hostnam によるファイル hostname への 'unlink' アクセスを阻止している

このバグは関連しているようです。インストール時に SELinux コンテキストがファイルに適切に適用されないという問題があります/etc/hostname。これは、ツールがhostnamectlファイルを操作できないことで現れます/etc/hostname。同じスレッドで次の回避策が提案されています:

$sudo restorecon -v /etc/hostname

注記:このパッチは Anaconda (インストール ツール) に適用されたため、今後は新規ユーザーにとってこの問題は発生しなくなるはずです。

答え2

おそらく原因は DHCP クライアントです。一般的な dhcpcd を使用している場合は、次の行を に追加することで解決できます/etc/dhcpcd.conf

nohook hostname

これにより、dhcpcd がシステムのホスト名を変更するスクリプトを呼び出すことがなくなります。

デフォルトでは、dhcpcd は存在するすべてのフックを実行します/lib/dhcpcd/dhcpcd-run-hooks(パスはシステムによって異なる場合があります)。 を使用すると、nohook特定のフックが無効になります。

関連情報