macOS: Wrong Bonjour name stuck in hostname
Solution 1:
The man page for hostname
says:
To keep the hostname between reboots, run `scutil --set HostName name-of-host'.
Also, the name in the Sharing prefs pane you mentioned, is that the name that isvisible right there when you open the pane, or the one you can edit when you click the "Edit..." (or similar - in German it's "Bearbeiten...") button?
Solution 2:
Use scutil
to set all three of the names that can exist for a macOS system.
Setting hostname via scutil
you can experiment with using a different name for each and figure which bonjour uses, which is the formal name and which maps to hostname
if the manual page isn’t clear.