Linux的DNS配置(resolv.conf)导致Unknown Host问题 博客分类: 故障排查
今天接到用户投诉说不定期会收到Unknown Host的错误,怀疑是应用服务器的DNS配置有问题,上应用服务器看了下/etc/resolv.conf,发现配置的第一行是:
options attempts:1 timeout:1
nameserver 10.10.10.10
查询相关配置说明发现DNS这块的逻辑是:
内网的DNS服务器的地址是10.10.10.10,应用服务器到内网的DNS去解析域名,内网DNS会在缓存中查找对应的域名解析,如果缓存中没有找到对应的,就会去上一级DNS域名解析器去查询,这个过程比较复杂,我改天写一篇详细的文章来仔细说明。
目前的配置的意思是应用服务器去获取域名的这个动作只尝试一次,超时时间是一秒。也就是说服务器去DNS服务器查询域名的时候,如果服务器没有在1秒之内收到应答就直接给应用程序报错。当本地DNS缓存没有请求域名的信息的时候,会去外网查询域名,这个过程会比较不稳定。很明显超时时间设置为1秒并且不重试的情况出现解析域名超时的情况会比较常见。下面是这两个参数的详细解释。把这行设置去掉,使用默认设置后,问题消失。
options
Options allows certain internal resolver variables to be modified. The syntax is
options option ...
where option is one of the following:
debug sets RES_DEBUG in _res.options.
ndots:n
sets a threshold for the number of dots which must appear in a name given to res_query(3) (see resolver(3)) before an initial abso‐
lute query will be made. The default for n is 1, meaning that if there are any dots in a name, the name will be tried first as an
absolute name before any search list elements are appended to it. The value for this option is silently capped to 15.
timeout:n
sets the amount of time the resolver will wait for a response from a remote name server before retrying the query via a different
name server. Measured in seconds, the default is RES_TIMEOUT (currently 5, see <resolv.h>). The value for this option is silently
capped to 30.
attempts:n
sets the number of times the resolver will send a query to its name servers before giving up and returning an error to the calling
application. The default is RES_DFLRETRY (currently 2, see <resolv.h>). The value for this option is silently capped to 5.