覆盖 TTL 设置外部 DNS 记录

覆盖 TTL 设置外部 DNS 记录

我有一个绑定版本,如下所示

9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6.1.2

我有两个域特定转发器,即 test.example.com 和 internal-test.example.cloud.com

需要解析域“test.example.com”中的特定 cname 的本地 DNS 客户端或解析器将由我的本地 DNS 服务器转发到配置的转发器,并且它们的响应也会被缓存。一切都很好,没问题。但是,我的问题是,对于 Fordwared 查询,外部 DNS 服务器以 TTL 值 60 进行回复。因此,我的内部 DNS 服务器仅将该响应缓存 60 秒。有什么办法可以覆盖我的内部 DNS 服务器的 TTL 吗?对于该特定域。

/etc/named.conf 如下所示

options {
        directory "/var/named";
        allow-transfer{"none";};
        allow-query {localhost; any;};
        dump-file "/var/log/named_dump.db";
        max-cache-ttl 300;
};

zone "test.example.com" IN {
        type forward;
        forwarders {11.1.2.17; 11.1.3.59;};
        forward only;
};

zone "internal-test.example.cloud.com" IN {
        type forward;
        forwarders {11.1.2.17; 11.1.3.59;};
        forward only;
};

zone "domain.local" in {
    type master;
    file "domain.local";
};



[root@dchockal ~]# dig test.example.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6.1.2 <<>> test.example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31197
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;test.example.com.   IN      A

;; ANSWER SECTION:
test.example.com. 60 IN      CNAME   internal-test.example.cloud.com.
internal-test.example.cloud.com. 60 IN A 121.1.2.22
internal-test.example.cloud.com. 60 IN A 121.1.2.23
internal-test.example.cloud.com. 60 IN A 121.1.4.24
internal-test.example.cloud.com. 60 IN A 121.1.4.25

;; Query time: 133 msec
;; SERVER: 11.4.152.28#53(11.4.152.28)
;; WHEN: Thu Dec 15 15:31:22 2016
;; MSG SIZE  rcvd: 175

答案1

BIND 无法做到这一点,而且这也不是一个好的做法。但也许您可以更新到 BIND 9.10.4?在这种情况下,您可以使用prefetch- 选项。这将迫使 BIND 在 TTL 到期前不久更新常用域上的缓存数据(可能可用于特定区域,但我无法测试这一点,因为此版本的 BIND 尚未在 Raspbian 上可用)。有关该选项的更多信息可以在这里找到:

https://serverfault.com/questions/536952/bind9-how-to-automatically-refresh-entry-after-entry-expires

例如,

options {
  ...
  prefetch 2 9;
};

将强制对当前位于缓存中的任何域进行缓存更新,在其 TTL 的最后 2 秒内进行查询,并且通常 TTL 超过 9 秒。

顺便说一句:如果你更新,请确保BIND 9.10.4是正确的。 -机制prefetch是在 9.10 中引入的,但是有一个丑陋的错误从 9.10.4 开始才被修复:

https://kb.isc.org/article/AA-01315/0/prefetch-performance-in-BIND-9.10.html

答案2

我不认为 BIND 具有该功能 - 仅减少 TTL ( cache-max-ttl),而不是增加(cache-min-ttl似乎不适用于我的 BIND,但您可以尝试一下,看看它是否适用于您的版本)。但我们可以创建一个我们自己的权威域。完成此操作后,我们可以在该域中为外部域创建 CNAME 记录。

test.mydomain.com CNAME test.example.com.

然后, 的查询将test.mydomain.com解析为 的 IP 地址test.example.com,并且可以根据需要配置 TTL。

理论上,我们可以重写BIND缓存的区域,然后将其创建为本地区域文件,设置TTL,然后重新启动BIND;但是,这是可怕的黑客行为。

该软件dnsmasq有一个选项 ,--min-cache-ttl=<time>其中time小于或等于 3600 秒。说明书上有警告。

--min-cache-ttl=<time>

Extend short TTL values to the time given when caching them. Note that
artificially extending TTL values is in general a bad idea, do not do it
unless you have a good reason, and understand what you are doing. Dnsmasq
limits the value of this option to one hour, unless recompiled.

你的问题听起来好像你知道自己在做什么。 Unbound也有这个功能。

cache-min-ttl: <seconds>

Time to live minimum for RRsets and messages in the cache. Default is 0.
If the minimum kicks in, the data is cached for longer than the domain owner
intended, and thus less queries are made to look up the data. Zero makes sure the
data in the cache is as the domain owner intended, higher values, especially more
than an hour or so, can lead to trouble as the data in the cache does not match
up with the actual data any more.

也许将 BIND 替换为 Unbound 或 dnsmasq,或者使用其中之一作为 BIND 的转发器。

相关内容