Bor*_*ree 3 linux dns networking centos
我有一个带有以下 /etc/hosts.conf 的 centOS 系统(嵌入式并且有很多二进制文件)。
$cat /etc/hosts
127.0.0.1 localhost localhost
Run Code Online (Sandbox Code Playgroud)
此外,主机被分配了一个 DNS 服务器,它返回一些无效的 IP 用于localhost的域名查找。但是由于某些网络限制,我无法避免连接到此 DNS。
我的问题是,当我已经有一个有效的 /etc/hosts 文件时,为什么系统会查询 DNS 以获取localhost?我怎么能阻止呢?
任何帮助将不胜感激。
检查您files
之前是否已列出dns
中的hosts
条目/etc/nsswitch.conf
。
[me@home]$ grep "^hosts" /etc/nsswitch.conf
hosts: files dns
Run Code Online (Sandbox Code Playgroud)
如果dns
是第一个,那么您的系统将始终查询 DNS 以在回退到/etc/hosts
.