FS#54682 - [netctl] netctl should set only the "Transient" Hostname

Attached to Project: Arch Linux
Opened by Stefan (steinwanderer) - Tuesday, 04 July 2017, 05:53 GMT
Last edited by Jouke Witteveen (jouke) - Monday, 31 July 2017, 13:12 GMT
Task Type Bug Report
Category Arch Projects
Status Closed
Assigned To Jouke Witteveen (jouke)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

If the "Hostname=" option is used in a profile, netctl uses "hostnamectl" to set the desired hostname. Since no options are given to hostnamectl, it will set all (3) hostnames. e.g:

Jul 03 14:47:06 systemd-hostnamed[4521]: Changed pretty host name to 'n/a'
Jul 03 14:47:06 systemd-hostnamed[4521]: Changed static host name to 'thinkpad-wls1'
Jul 03 14:47:06 systemd-hostnamed[4521]: Changed host name to 'thinkpad-wls1'
Jul 03 14:47:06 network[4306]: Started network profile 'wireless-wpa'

netctl imo should really not do that and rather set the the "transient hostname" only, like systemd-networkd or network-manager do it for instance. Also if the "pretty hostname" is cleared like that, it messes with your bluetooth.

Additional info:
* package version(s)

netctl 1.12-2

* config and/or log files etc.

Jul 03 14:47:06 systemd-hostnamed[4521]: Changed pretty host name to 'n/a'
Jul 03 14:47:06 systemd-hostnamed[4521]: Changed static host name to 'thinkpad-wls1'
Jul 03 14:47:06 systemd-hostnamed[4521]: Changed host name to 'thinkpad-wls1'
Jul 03 14:47:06 network[4306]: Started network profile 'wireless-wpa'

Steps to reproduce:

1) setting "Hostname=whatever" in a profile and start it.
2) check the actual hostname with "hostnamectl"

IMHO it is trivial to fix:

--- src/lib/ip.orig 2017-03-14 18:17:53.000000000 +0100
+++ src/lib/ip 2017-07-04 07:15:47.975289310 +0200
@@ -149,7 +149,7 @@
done

if [[ $Hostname ]]; then
- if ! do_debug hostnamectl set-hostname "$Hostname"; then
+ if ! do_debug hostnamectl set-hostname --transient "$Hostname"; then
report_error "Cannot set the hostname to '$Hostname'"
return 1
fi
This task depends upon

Closed by  Jouke Witteveen (jouke)
Monday, 31 July 2017, 13:12 GMT
Reason for closing:  Implemented
Additional comments about closing:  b1b03d8
Comment by Jouke Witteveen (jouke) - Thursday, 06 July 2017, 09:00 GMT
Thanks for your report!

This sounds reasonable, but we don't want to break existing configurations. Can we be sure that we will not? The following excerpt from the hostnamectl manpage appears of interest:

[T]he transient hostname [...] is a fallback value received from network configuration. If a static hostname is set, and is valid (something other than localhost), then the transient hostname is not used.

I am assuming that we do not want Hostname= to be have no effect when a static hostname is set? Maybe `set-hostname --static --transient "$Hostname"`?
Comment by Stefan (steinwanderer) - Friday, 07 July 2017, 17:31 GMT
I would rather tend to "--transient" only, because imho this is the "right" way to do it. But another thing is, that netctl does not revert the hostname back after a connection goes down. I think the handling of the hostname could/should be more flexible overall.

How about getting the hostnamectl stuff out of "/usr/bin/netctl" and putting it into a separately hook instead?
This would give some freedom on how to handle the hostname.
Comment by Stefan (steinwanderer) - Saturday, 08 July 2017, 11:10 GMT
How about introducing a new config option for that? I'm sure it can be done better, but here is my try:

UseHostname= [requires Hostname=]
One of ‘transient’, ‘static’ or ’none’. If not set or empty, all hostnames are set (Default).

Comment by Jouke Witteveen (jouke) - Monday, 31 July 2017, 13:10 GMT
Somewhat contrary to the suggestion in the hostnamectl manpage that the static hostname overrides the transient hostname, the Red Hat Networking Guide[1] states that the transient hostname defaults to the static hostname. Let's try going with the transient hostname as you initially suggested before introducing more complex logic.

In reverting the hostname we could add more complex checks such as

[[ $Hostname == "$(hostnamectl --transient)" ]]

but I prefer to keep it simple/dumb for now. Of course, you could already use hooks for setting hostnames if you want total control.

Thanks for your contribution!


[1] https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/ch-Configure_Host_Names.html

Loading...