35

I've heard that changing the hostname in new versions of fedora is done with the hostnamectl command. In addition, I recently (and successfully) changed my hostname on Arch Linux with this method. However, when running:

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

The changes are not preserved after a reboot (contrary to many people's claims that it does). What is wrong?

  • I really don't want to edit /etc/hostname manually.

I should also note that this is a completely stock fedora. I haven't even gotten around to installing my core apps yet.

  • This had similar info regarding the issue as well: ask.fedoraproject.org/en/question/37413/… & this: dbaora.com/install-fedora-20 – slm Oct 16 '14 at 2:13
  • Indeed, this is one of my sources. However, none of the solutions I could extract from that page worked... – PythonNut Oct 16 '14 at 2:26
  • How recently did you install/setup this system? Has the problem been present since installation? Also are there any errors w/ those hostnamectl commands? The link to the bugzilla bug that somethingsomething posted seems like your best lead. – slm Oct 18 '14 at 23:07
  • I installed on 10/1/14, and since then the hostnamectl commands did not work, but now they do. – PythonNut Oct 18 '14 at 23:15
  • The bug linked to in the accepted solution was just an unfortunate timing for you. They've fixed it upstream and it should be working its way out for future users. – slm Oct 18 '14 at 23:18
39

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.

3

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.

  • 1
    For both my 21 and rawhide installs, /etc/dhcpd.conf does not exist. In addition, systemctl status dhcpcd returns not-found (Reason: No such file or directory) – PythonNut Oct 16 '14 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.