Am 16.01.2022 um 22:53 schrieb Thomas Cameron <thomas.cameron@camerontech.com>:

On 1/16/22 15:00, Peter Boy wrote:
Do you want to set the hostname at every boot?

Usually you set the static hostname once using "hostnamectl set-hostname <FQDN>“.  „fedora“ is the transient hostname. DHCP client uses the static hostname to request an IP.

But maybe I didn't get what exactly you want to do.

I have DNS set up such that every host that gets a dynamic address gets the hostname hostXXX.tc.camerontech.com, like this:

172.31.100.100    host100.tc.camerontech.com
172.31.100.101    host101.tc.camerontech.com
172.31.100.102    host102.tc.camerontech.com
172.31.100.103    host103.tc.camerontech.com

…...

I have a few setup scripts which really need an accurate hostname value set, so this is really frustrating.


I was already afraid that I had overlooked something essential. :-)

The default configuration rather follows the opposite principle. The hostname should be well defined and independent of changing IP addresses. I guess the only way will be to determine the hostname via script and call networkctl with it. Unfortunately rclocal is lost. You use KVM on Fedora Server that includes libvirt. It provides hooks which you can use to automatically execute scripts when libvirt finishes initialisation. See https://libvirt.org/hooks.html. As an example I use that to fix some issues with systems-resolved and libvirt (https://docs.stg.fedoraproject.org/en-US/fedora-server/virtualization-install/)

You can also use it to trigger /etc/profile.d/hostname.sh without login. Systemd also provides a replacement for rc.local, but last time I checked it, it was quite tricky.