[systemd-devel] systemd/hostnamed: setting the hostname and using it in the DHCP Discover

Andrey Yurovsky yurovsky at gmail.com
Sat Jul 29 15:36:37 UTC 2017


On Sat, Jul 29, 2017 at 1:26 AM, Mantas Mikulėnas <grawity at gmail.com> wrote:
> On Sat, Jul 29, 2017 at 9:00 AM, Andrey Yurovsky <yurovsky at gmail.com> wrote:
>>
>> However I see the DHCP client use the original hostname the first time
>> my target boots (I captured traffic and checked the DHCP Discover
>> contents). When I reboot the newly-booted system, /etc/hostname is
>> already updated so everything looks right on the wire. It feels like
>> systemd-networkd is using the hostname that was read at systemd init
>> (in main.c) rather than checking what it's set to, but that's just
>> speculation (I need to dig in further).
>
>
> In that case, could you try setting it via `hostnamectl` instead?

I've tried that but hostnamectl wants to talk to systemd1 and
hostnamed so I either try invoking it too early and communication
fails or too late and hostnamectl succeeds but the original hostname
is still used in the DHCP Discover.

The documentation for hostnamectl instructs me to use
systemd-firstboot to initialize the hostname but at this time that
facility isn't a good fit for my system so I'm hoping there's some
reasonable way to do this on startup. It's very likely that I'm
missing something obvious here but I don't yet understand the sequence
of events between systemd initializing and reading /etc/hostname, my
own call to hostname(2) via the shell, hostnamed actually starting,
and what systemd-networkd chooses to put in the Hostname field of the
DHCP DIscover packet.


More information about the systemd-devel mailing list