主机对本地主机进行不必要的 DNS 查找
我有一个 centOS 系统(嵌入式并且有很多二进制文件),带有以下 /etc/hosts。
$cat /etc/hosts
127.0.0.1 localhost localhost
此外,主机还被分配了一个 DNS 服务器,该服务器返回一些无效的 IP,用于 localhost 的域名查找。但由于某些网络限制,我无法避免与此 DNS 的连接。
我的问题是,当我已经有了有效的 /etc/hosts 文件时,为什么系统会在 DNS 中查询 localhost?我怎样才能阻止这种情况呢?
任何帮助将不胜感激。
I have a centOS system(embedded and has very binaries) with the following /etc/hosts.
$cat /etc/hosts
127.0.0.1 localhost localhost
Also the host is assigned a DNS server which returns some invalid IP for the domain name lookup of localhost. But I cannot avoid a connection to this DNS due to some network restrictions.
My question is, when I already have a valid /etc/hosts file why is the system querying the DNS for localhost? And how can I stop that?
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查
/etc/nsswitch.conf
。如果
dns
先出现,那么您的系统将始终查询 DNS 来解析主机名,然后再回退到/etc/hosts
。Check that you have
files
listed beforedns
for thehosts
entry in/etc/nsswitch.conf
.If
dns
comes first, then your system will always query DNS to resolve hostnames before falling back to/etc/hosts
.