1

我有一个使用 musl libc 的 alpine linux 系统,因此没有/etc/nsswitch.conf.

根据这个系统上的 tcpdump,net.LookupIP("localhost")实际上是查询localhost.a.b.c,其中a.b.c取自domain a.b.cin /etc/resolv.conf。但是如果我添加一个/etc/nsswitch.confwith hosts: files dns,它会正确地localhost/etc/hosts.

localhost据我所知,在 DNS 中查找域时,没有任何 libc 实现会尝试添加域。那么(a)这样做是否有充分的理由或者是一个错误?(b) 有没有办法在不添加 nsswitch.conf 并且仍然只使用名称的情况下解决它localhost

编辑更多细节:

ldd ./dnstest
    /lib/ld-musl-armhf.so.1 (0x76f2c000)
    libc.so => /lib/ld-musl-armhf.so.1 (0x76f2c000)

所以是的,存在对libc.so. 我也在构建命令行中CGO_ENABLED=1尝试过这个。CGO_ENABLED=0

4

0 回答 0