Host file entries no longer work after fresh install

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.

Any ideas?

Manjaro is using the same default settings as EOS so it is something else that is bugging you.

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.

Hmm - I would expect them to be the same - after all it is the same source.

The config on my system works without issues

$ cat /etc/nsswitch.conf 
# Name Service Switch configuration file.
# See nsswitch.conf(5) for details.

passwd: files systemd
group: files [SUCCESS=merge] systemd
shadow: files systemd
gshadow: files systemd

publickey: files

hosts: mymachines mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] files myhostname dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

netgroup: files

The filesystem package which provides some basic defaults has nsswitch.conf with content

# Name Service Switch configuration file.
# See nsswitch.conf(5) for details.

passwd: files systemd
group: files [SUCCESS=merge] systemd
shadow: files systemd
gshadow: files systemd

publickey: files

hosts: mymachines mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] files myhostname dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

netgroup: files

Upstream Arch

# Name Service Switch configuration file.
# See nsswitch.conf(5) for details.

passwd: files systemd
group: files [SUCCESS=merge] systemd
shadow: files systemd
gshadow: files systemd

publickey: files

hosts: mymachines resolve [!UNAVAIL=return] files myhostname dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

netgroup: files

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…

I have the same problem. I can find localhost with

host localhost

but it doesn’t find my custom entries

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.

[xabbu@xabbutest ~]$ cat /etc/nsswitch.conf 
# Name Service Switch configuration file.
# See nsswitch.conf(5) for details.

passwd: files systemd
group: files [SUCCESS=merge] systemd
shadow: files systemd
gshadow: files systemd

publickey: files

hosts: mymachines mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] files myhostname dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

netgroup: files
[xabbu@xabbutest ~]$ cat /etc/hosts 
# Host addresses
127.0.0.1  localhost
127.0.1.1  xabbutest
::1        localhost ip6-localhost ip6-loopback
ff02::1    ip6-allnodes
ff02::2    ip6-allrouters

192.168.1.20 thor
[xabbu@xabbutest ~]$ ping -c 2 thor 
PING thor (192.168.1.20) 56(84) bytes of data.
From thor (192.168.1.20) icmp_seq=1 Destination Host Unreachable
From thor (192.168.1.20) icmp_seq=2 Destination Host Unreachable

--- thor ping statistics ---
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1006ms
pipe 2

Since I don’t use IP 192.168.1.20, it is unreachable.

1 Like