I just did a fresh install of Manjaro and now entries in /etc/hosts no longer work. For example, I have a file server on 192.168.1.20 named thor, so in my /etc/hosts I have:
192.168.1.20 thor
However, it seems not to resolve.
In addition, on another machine that i’ve been running Manjaro on for while, after the last update hosts broke, because “files” was near the end of the hosts line in /etc/nsswitch.conf. I was able to fix this by moving files to the start of the line before mymachines.
However, this appears to have no effect on the fresh install. Something seems totally borked, but no idea what. I had to move to EndeavourOS where /etc/hosts works as expected.
Not so. Actually, Manjaro’s /etc/nsswitch.conf file is different than EOS’s. Also, fresh install of EOS, host entries work. Fresh install of Manjaro, they do not. So something must be different.
I can see there is some subtle differences where the most prominent is the [NOTFOUND=return] which - if I read it correct - will return before reaching the files entry.
I am not using a hosts file for my network - I use a raspberry pi and a subdomain on one of my internet domains - simply because it became too much work to get hostnames and IP to correlate.
EOS is using the upstream arch version. On an existing Manjaro install, I am able to get host file entries working again by putting files up before mdns_minimal. However, on a FRESH install of manjaro, this trick does not work. I am out of ideas…
The host program will not check local files. Similar to dig, it will only query the DNS server configured in /etc/resolv.conf . You can specify a DNS Server, for example
host localhost 8.8.8.8
and of course Google DNS will not resolve localhost. But if you configure a DNS Server in your /etc/resolv.conf that can read your /etc/hosts file, the host program can resovle your custom entries. ( For example the systemd-resolved stub is able to do that.)
The /etc/nsswitch.conf file is only used by programs that use the glibc resolver. Many programs on Linux do that, but not all.
Unfortunately you did not tell us which flavor (DE) of Manjaro you installed and if you use systemd-resolved and which program you used to test it.
I did a fresh install of Manjaro XFCE (manjaro-xfce-21.2.0-211220-linux515.iso), did an update and /etc/hosts entries work out of the box. It might be important to note that the XFCE edition doesn’t use systemd-resolved. Which means, that not all program will use the /etc/hosts . But for example ping uses the glibc resolver, which uses /etc/nsswitch.conf . The mymachines entry is used for local containers, that are registered thru systemd-machined. mdns4_minimal will only be used if the DNS name, that needs to be resolved, ends in .local . This ending is used by mDNS and should not be used for something else. Since Manjaro XFCE doesn’t use systemd-resolved the resolve entry is unavailable and is skipped. After that, files is used, which means /etc/hosts is checked.