nsswitch.conf 与 host.conf

Des*_*ume 12 linux networking ubuntu

假设该/etc/nsswitch.conf文件包含

hosts: files dns
Run Code Online (Sandbox Code Playgroud)

/etc/host.conf文件有

order bind,hosts
Run Code Online (Sandbox Code Playgroud)

那么系统将按照什么顺序使用/etc/hostsDNS 查找来解析主机名?换句话说,这两个配置文件中哪个优先?

Ale*_*ach 14

/etc/nsswitch.conf是当今域名解析的默认文件。我的/etc/host.conf文件顶部有以下行:-

# The "order" line is only used by old versions of the C library.
Run Code Online (Sandbox Code Playgroud)

nsswitch.conf我的 Debian 机器上几乎所有东西都使用它来进行名称解析。因此,鉴于文件中的上述行,默认名称解析顺序是先检查/etc/hosts,然后使用配置的名称服务器/etc/resolv.conf进行 DNS 查找。

最近(从 Ubuntu 11.10 开始),/etc/resolv.conf默认配置为使用本地主机接口 (127.0.0.1),其中守护程序dnsmasq在端口 53 上侦听 DNS 请求。这通常会按照 LAN 的 DHCP 服务器的配置进行 DNS 解析,但这可以在操作系统的网络配置 GUI 中手动覆盖。

注意:您没有提到您使用的是什么操作系统,以上来自个人使用 Debian Ubuntu 的经验。不同版本的 Linux 上的默认值可能不同