优化 resolv.conf

DNS lookup 在把域名解析成 IP 过程中耽误了不少时间,尤其是访问比较复杂的网站的时候,比如某个页面包含多个 url,一次请求需要做多次 DNS 解析,并且从用户浏览器到 DNS server,以及 DNS server 和 DNS server 之间都会产生延迟或有可能发生的错误,Google 意识到了这点,作为 Google 雄心勃勃 make the web faster 计划的一部分,Google 去年年底发布了自己的 Google Public DNS,对于一些在我们的 VPS 上使用 vpn 浏览网页的用户,在自己 VPS 里面加入 Google Public DNS 可以加快访问网站的速度(虽然作为用户来说速度差异感觉不明显)。打开 Linux 的 inlcude/resolv.h 文件可以发现里面定义了可以追踪的 DNS server 数目:

$ vi /usr/include/resolv.h

/*
 * Global defines and variables for resolver stub.
 */
# define MAXNS                  3       /* max # name servers we'll track */

所以 /etc/resolv.conf 定义了3个 name server,option rotate 选项指在这3个 dns server 之间轮回查询,option timeout:1 选项设定 lookup timeout 的时间为1秒(默认为5秒),下面是 VPSee 使用的 DNS server 和 resolv.conf 配置:

$ cat /etc/resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 4.2.2.2
option rotate 
option timeout:1

评论 (5 Comments)

  1. 如果把MAXNS改成6就可以增加/etc/resolv.conf中的nameserver了么

  2. 将MAXNS改大,就可以增加nameserver了么

  3. option rotate
    是什么意思?一直没明白

  4. 标准答案:
    rotate

    sets RES_ROTATE in _res.options, which causes round robin selection of nameservers from among those listed. This has the effect of spreading the query load among all listed servers, rather than having all clients try the first listed server first every time.

  5. 不应该是
    options rotate
    options timeout:1 吗?

发表评论