[systemd-devel] How do you set the machine's domain name with systemd?

Lennart Poettering lennart at poettering.net
Tue Feb 12 18:50:32 PST 2013

On Wed, 13.02.13 05:42, Adam Nielsen (a.nielsen at shikadi.net) wrote:

> >Use hostnamectl, assuming your systemd version is new enough:
> >
> >http://www.freedesktop.org/software/systemd/man/hostnamectl.html
> Thanks for the suggestion, but unfortunately this doesn't seem to work:
> $ hostnamectl set-hostname korath.my.domain.com

So, we currently clean up names here a bit too drastically.

That said, I am a bit uncertain about the whole fqdn-as-kernel-hostname
thing. That's a concept that only makes sense on single-networked hosts,
and mingles protocol-specific semantics of DNS with a very generic
concept. Or to put this differently: I am pretty sure gethostname()
should return something that is useful for mDNS, for Bluetooth host
names, as well as per-interface hostnames. i.e. "foobar" should appear
as "foobar.local" on mDNS, as "foobar.waldo.com" on eth0, and as
"foobar.quux.net" on eth1, as well as just "foobar" on Bluetooth. But if
the fqdn is used in gethostname() then suddenly all this makes a ton
less sense, on mDNS we'd have to shorten things, on some interfaces
might now match 1:1 but on others not at all anymore, and Bluetooth
suddenly sees IP pecularities spill into its BT host name.

I am aware that many systems use fqdn as hostnames, but this doesn't
really sound like something we should advocate, as it it only makes
sense within very specific networks. Currently, "hostnamectl
set-hostname" won't accept it at all, but you can write it manually to

I am figure "hostnamectl set-hostname" is currently a bit too drastic,
but I am not fond at all of the idea of adovcate this
fqdn-as-kernel-hostname nonsense any further, it sounds like the wrong
idea, from a very narrow IP+DNS mindset...

> $ cat /etc/hostname
> korathmydomaincom
> $ pacman -Qi systemd | grep Ver
> Version        : 197-4
> At a suggestion from my distro's discussion forum, manually editing
> /etc/hostname and putting the FQDN back in there works.  So I'm not
> sure whether this is a bug in hostnamectl or whether editing
> /etc/hostname is still the preferred way to set a machine's FQDN.
> Also for the record the "localhost.localdomain" was because my short
> hostname was listed against in /etc/hosts.  Removing that
> fixed that issue.

For that we have nss-myhostname these days. /etc/hosts really should
stay unmodified.


Lennart Poettering - Red Hat, Inc.

More information about the systemd-devel mailing list