Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automate updating /etc/hosts #12793

Closed
mikhailnov opened this issue Jun 13, 2019 · 3 comments
Closed

automate updating /etc/hosts #12793

mikhailnov opened this issue Jun 13, 2019 · 3 comments

Comments

@mikhailnov
Copy link
Contributor

Curently hostnamectl set-hostname <new hostname> leaves old hostname in /etc/hosts, what may lead to unsertain behaviour in different situation, e.g. sudo may take long to start, samba's net ads join will work incorrectly etc.

I would propose to automate changing /etc/hosts at least when there is old hostname in it and so we may change it to a new one.

Another aspect is that we need to keep the following format:
127.0.0.1 <FQDN> <short>
(e.g. 127.0.0.1 pc.domain.loc pc)
as recommended in hostname(1). net ads join fails to work correctly when it is 127.0.0.1 <short> <FQDN>, it wants to see 127.0.0.1 <FQDN> <short> (https://ubuntuforums.org/showthread.php?t=2346398&p=13588177#post13588177, https://bugzilla.rosalinux.ru/show_bug.cgi?id=9962)

@poettering
Copy link
Member

We have provided nss-myhostname for this purpose for a long time. It maps the local hostname to 127.0.0.1 (or a more appropriate local IP address) in absence of any other record. Please work with your distribution to enable it, many already do. With the module enable the local hostname never has to be listed in /etc/hosts and it stay always resolvable.

For further details see:

https://www.freedesktop.org/software/systemd/man/nss-myhostname.html

(Some installers still write out the entry into /etc/hosts even though nss-myhostname is already enabled by default. They should be fixed to simply not do that anymore.)

Anyway, closing, since this is already available in a better, more efficient more dynamic version.

@mikhailnov
Copy link
Contributor Author

mikhailnov commented Jun 17, 2019

Thank you, that seems to be a good solution that we can integrate to ROSA distribution out of the box (UPD: it was already), it seems to do what I wanted to, didn't know about it.
I think that not writing anything to /etc/hosts is not a good idea as some software or scripts may still rely on that, but if I understood correctly, if myhostname goes after files in /etc/nsswitch.conf, the reply from nss-hostname will have a higher priority than what is written in /etc/hosts, am I right?

@poettering
Copy link
Member

no, it's the other way round: first listed NSS module that considers itself authoritative for a name wins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants