sgerrand / alpine-pkg-glibc

A glibc compatibility layer package for Alpine Linux
2.07k stars 280 forks source link

glibc-dependent applications ignore /etc/hosts file #4

Closed frol closed 8 years ago

frol commented 8 years ago

Missing /etc/nsswitch.conf configuration results in that glibc-dependent applications ignore /etc/hosts contents entirely. See the reproduction here:

/ # /mnt/ping `hostname`
ping: 2432f83035d9: Name or service not known

/ # ping `hostname`
PING 2432f83035d9 (172.17.0.2): 56 data bytes
64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.043 ms

NOTE: /mnt/ping utility was copied from my glibc-based host system.

I have added the following fix in frolvlad/alpine-glibc long time ago, and it proved to work fine for many people since then:

echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf
andyshinn commented 8 years ago

Do we know where /etc/nsswitch.conf usually comes from? It is possible it is just missed from the generated glibc package or builder. I'll check soon to see if this is the case.

frol commented 8 years ago

It seems to be a base OS layout:

filesystem package owns the file in Arch Linux

$ yaourt -Qo /etc/nsswitch.conf
/etc/nsswitch.conf is owned by filesystem 2015.09-1

No package is associated with the file in Debian and Ubuntu:

$ dpkg -S /etc/nsswitch.conf
dpkg-query: no path found matching pattern /etc/nsswitch.conf
frol commented 8 years ago

Wierd, but /etc/nsswitch.conf is created as a symlink:

/ # ls -la /etc/nsswitch.conf
lrwxrwxrwx    1 root     root            35 Feb 12 05:35 /etc/nsswitch.conf -> /home/builder/package/nsswitch.conf
andyshinn commented 8 years ago

Huh... I'm pretty sure I just did a cp -a... I'll look at it again in a couple days.

frol commented 8 years ago

cp -a will copy a symlink if it is a symlink, but in this case, we want to have just a regular file. Could you please remove -a flag?

andyshinn commented 8 years ago

Give the latest unreleased tag a try.

frol commented 8 years ago

It works!