我最近更改了我的 Linux 发行版 (Manjaro),并且在
/etc/hosts
中定义并以 .local
结尾的本地域不再起作用。
# /etc/hosts
# Host addresses
127.0.0.1 localhost
127.0.0.1 hello.local
127.0.0.1 hello.domain.local
127.0.0.1 hello.other
$ ping hello.local
ping: hello.local: Nom ou service inconnu
$ ping hello.other
PING hello.other (127.0.0.1) 56(84) octets de données.
64 octets de localhost (127.0.0.1) : icmp_seq=1 ttl=64 temps=0.012 ms
...
$ ping hello.domain.local
PING hello.domain.local (127.0.0.1) 56(84) octets de données.
64 octets de localhost (127.0.0.1) : icmp_seq=1 ttl=64 temps=0.012 ms
...
这不仅仅适用于 tld .local 的子域:
hello.local
。
如果它是子子域:
hello.domain.local
,它可以工作。
此外,如果顶级域名不是 (.local) 而是 .other :
hello.other
,它也可以工作。
我哪里漏掉了什么?
首先,备份你的 nsswitch.conf -> sudo cp /etc/nsswitch.conf /etc/nsswitch.conf.bk
然后,转到 /etc/nsswitch.conf 并
替换这条线
主机:mymachines mdns4_minimal [NOTFOUND=return] 解析 [!UNAVAIL=return] 文件 myhostname dns
到
主机:文件 mdns4_minimal [NOTFOUND=返回] dns