0

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?

gillesB
  • 121
  • 3
  • 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 – David Apr 06 '23 at 08:16
  • @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 Apr 06 '23 at 09:53
  • 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. – gillesB Apr 06 '23 at 09:54

0 Answers0