How to permanently change hostname in Fedora 21

The command to set the hostname is definitely, hostnamectl.

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

Here's an additional source that describes this functionality a bit more, titled: Correctly setting the hostname - Fedora 20 on Amazon EC2.

Additionally the man page for 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.

There is a bug in Fedora 21 where SELinux prevents hostnamectl access, found here, titled: Bug 1133368 - SELinux is preventing systemd-hostnam from 'unlink' accesses on the file hostname.

This bug seems to be related. There's an issue with the SELinux contexts not being applied properly to the file /etc/hostname upon installation. This manifests in the tool hostnamectl not being able to manipulate the file /etc/hostname. That same thread offered this workaround:

$sudo restorecon -v /etc/hostname

NOTE: That patches were applied to Anaconda (the installation tool) so that this issue should go away in the future for new users.


The likely cause for this is your dhcp client. If you're using dhcpcd, which is common, the solution is to add the following line to /etc/dhcpcd.conf:

nohook hostname

This prevents dhcpcd from calling out to the script which changes your system hostname.

By default, dhcpcd runs all the hooks present /lib/dhcpcd/dhcpcd-run-hooks (the path may differ on your system). Using nohook disables specific ones.