Score:0

How to correctly configure nss-myhostname?

cn flag

I am configuring a minimal Ubuntu-Desktop (vanilla Ubuntu Server + the meta package ubuntu-desktop-minimal) and the user/admin should be able to easily change the hostname, as this is needed from time to time.

When changing the hostname via GNOME (or systemd for that matter), it is only changing /etc/hostname but not /etc/hosts. The recommended systemd-way to avoid problems due to this behavior, is using nss-myhostname. Although it seems to be controversial in the Ubuntu community (see post and links) I installed libnss-myhostname (and libnss-resolve, but I am unsure if this is actually needed).

Anyway nss-myhostname does not have the expected effect.

I commented the following line in the /etc/hosts out: 127.0.1.1 108-0001

And I changed the hosts line in /etc/nsswitch.conf to: hosts: resolve [!UNAVAIL=return] files myhostname dns.

When I test my setting with getent ahosts `hostname` as suggested by the man-page I get the following result:

$ getent ahosts `hostname`
fe80::d24c:c1ff:fe05:bd71%2 STREAM 108-0001
fe80::d24c:c1ff:fe05:bd71%2 DGRAM
fe80::d24c:c1ff:fe05:bd71%2 RAW
192.168.1.55    STREAM
192.168.1.55    DGRAM
192.168.1.55    RAW

At least the hostname can be resolved but it is not resolved to the expected 127.0.0.2 and ::1. What am I doing wrong or are my expectations wrong?

David avatar
cn flag
See the info here. There are know issues with that app. https://askubuntu.com/questions/453072/what-is-nss-myhostname-and-why-is-it-not-installable
gillesB avatar
cn flag
@David I have seen that post, but the bug reports seem to be about a warning issued by `systemd-hostnamed`. Well and if you follow the links an opinion by Steve Langasek that e.g. `hostnamectl set-hostname` should modify `/etc/hosts` and therefore `nss-myhostname` is not a good option. I get his point, but it does not solve my issue. Because ten years later, admins still need to remember to change the hostname at two locations and not just one, which simply is error prone.
gillesB avatar
cn flag
And as general advice, do not leave the `hosts` line in `/etc/nsswitch.conf` empty. This breaks sudo and you need to find a different way in changing it back.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.