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

Andrey Yurovsky yurovsky at gmail.com
Sat Jul 29 06:00:50 UTC 2017


On Fri, Jul 28, 2017 at 10:46 PM, Mantas Mikulėnas <grawity at gmail.com> wrote:
>
>
> On Sat, Jul 29, 2017, 08:13 Andrei Borzenkov <arvidjaar at gmail.com> wrote:
>>
>> 28.07.2017 22:08, Andrey Yurovsky пишет:
>> >
>> > Is there a correct way to replace or otherwise set the hostname and
>> > have systemd use it from the beginning and ensure that the DHCP client
>> > specifies it in option 12?
>> >
>>
>> Use generator to create /etc/hostname before systemd starts.
>

Thanks, I tried that and:

> But afaik, generators only run before units are processed, but still after
> applying the general config?

That, I believe, is what I observed.

> That said... Might the problem be that you only update the config in /etc
> but don't apply it to the kernel via `hostname`? DHCP clients don't really
> care about /etc/hostname.

In my tests I have a shell script that generates the desired hostname
string, writes it to /etc/hostname, and then runs hostname -F
/etc/hostname which as I understand it will read that back and call
hostname(2). That script is invoked by my unit that runs via the
network-pre.target.

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).

> --
>
> Mantas Mikulėnas <grawity at gmail.com>
> Sent from my phone
>
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>


More information about the systemd-devel mailing list