【问题标题】:host doing unnecessary dns lookup for localhost主机对 localhost 进行不必要的 dns 查找
【发布时间】:2012-02-29 19:41:45
【问题描述】:

我有一个带有以下 /etc/hosts 的 centOS 系统(嵌入式并且有很多二进制文件)。

$cat /etc/hosts
127.0.0.1 localhost localhost

还为主机分配了一个 DNS 服务器,该服务器返回一些无效的 IP 用于 localhost 的域名查找。但由于某些网络限制,我无法避免与此 DNS 的连接。

我的问题是,当我已经有一个有效的 /etc/hosts 文件时,为什么系统会在 DNS 中查询 localhost?我该如何阻止呢?

任何帮助将不胜感激。

【问题讨论】:

    标签: linux networking dns centos


    【解决方案1】:

    检查 /etc/nsswitch.conf 中的 hosts 条目是否在 dns 之前列出了 files

    [me@home]$ grep "^hosts" /etc/nsswitch.conf 
    hosts:      files dns
    

    如果 dns 先出现,那么您的系统将始终查询 DNS 以解析主机名,然后再返回到 /etc/hosts

    【讨论】:

    • 谢谢肖恩。像魅力一样工作:)
    猜你喜欢
    • 1970-01-01
    • 2019-11-09
    • 2016-04-15
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 2015-06-03
    • 1970-01-01
    相关资源
    最近更新 更多