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.

나는 또한 이것이완전히재고 페도라. 아직 핵심 앱을 설치하지도 못했습니다.

답변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이 호스트 이름 파일에 대한 '링크 해제' 액세스를 방지합니다..

이 버그는 관련이 있는 것 같습니다. /etc/hostname설치 시 SELinux 컨텍스트가 파일에 제대로 적용되지 않는 문제가 있습니다 . 이는 도구가 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특정 기능이 비활성화됩니다.

관련 정보