如何禁用 DNS 缓存或覆盖某个主机名的 TTL?

n.s*_*.st 5 munin dns debian

我已经通过使用脚本自动更新我的域之一的子域的 A 记录来设置我自己的动态 DNS 服务。
具有动态 IP 地址的主机运行一个 Munin 节点,我每隔五分钟远程读取一次。
不幸的是,我的域名注册商不允许 TTL 值小于 3600,因此远程 Munin 节点的 IP 会缓存一个小时,并且只要节点的动态 IP 更改,连接就会失败长达所述小时。

有没有办法覆盖我的注册商的 DNS 服务器报告的 TTL,这样服务器每次连接到 Munin 节点时都会重新解析 IP?

slm*_*slm 5

如果您使用的动态 DNS 服务仅允许 3600 的 TTL,那么您唯一的选择就是切换提供商。除非 DDNS 服务提供商为您提供控制它的选项,否则真的没有任何方法可以控制 TTL。

检查 TTL

顺便说一下,要检查给定条目的 TTL 是什么,您可以使用dig以下开关。

例子

$ dig +nocmd www.google.com +noall +answer | tail -1
www.google.com.     137 IN  A   74.125.225.82

$ dig +nocmd www.google.com +noall +answer | tail -1
www.google.com.     135 IN  A   74.125.225.115
Run Code Online (Sandbox Code Playgroud)

所以这个响应的 TTL 是 137 秒。等待约 2 秒并再次运行它显示 135 秒。TTL 表示距离 DNS 条目过期还剩多少时间,我们需要去查询域的权威服务器。

检查最大 TTL

如果我们要查询权威服务器。

$ dig @ns1.google.com +nocmd www.google.com +noall +answer | tail -1
www.google.com.     300 IN  A   74.125.225.210
Run Code Online (Sandbox Code Playgroud)

所以这个条目的实际 TTL 是 300 秒。

注意:权威服务器也称为SOA - Start of Authority

SOA信息

您可以进一步查询域以获取 SOA 信息。

$ dig +nocmd dyndns.org any +multiline +noall +answer
dyndns.org.     596 IN SOA ns1.dyndns.org. hostmaster.dyndns.org. (
                863998266  ; serial
                600        ; refresh (10 minutes)
                300        ; retry (5 minutes)
                604800     ; expire (1 week)
                600        ; minimum (10 minutes)
                )
dyndns.org.     85904 IN NS ns5.dyndns.org.
dyndns.org.     85904 IN NS ns1.dyndns.org.
dyndns.org.     85904 IN NS ns2.dyndns.org.
dyndns.org.     85904 IN NS ns3.dyndns.org.
dyndns.org.     85904 IN NS ns4.dyndns.org.
dyndns.org.     12268 IN MX 10 mail.dyndns.com.
dyndns.org.     12268 IN MX 20 mx2.mailhop.org.
dyndns.org.     179 IN A 204.13.248.116
Run Code Online (Sandbox Code Playgroud)

更改 TTL

更改 DNS 条目的 TTL(在您的注册商可能提供的某种 API 之外)的唯一方法是通过服务器。

例子

Bind 中,您可以像这样设置区域文件:

;Zone file for liquidweb.com
$TTL 14400
@      86400    IN      SOA     ns.liquidweb.com. admin.liquidweb.com. (
2009022402      ; serial, todays date+todays
86400           ; refresh, seconds
7200            ; retry, seconds
3600000         ; expire, seconds
86400 )         ; minimum, seconds
liquidweb.com. 86400 IN NS   ns.liquidweb.com.
liquidweb.com. 86400 IN NS   ns1.liquidweb.com.
liquidweb.com.  IN A   209.59.139.21
localhost  IN A   127.0.0.1
liquidweb.com.  IN MX 0   liquidweb.com.
mail  IN CNAME  liquidweb.com.
www  IN CNAME   liquidweb.com.
ftp  IN A   209.59.139.21
cpanel  IN A   209.59.139.21
webmail  IN A   209.59.139.21
Run Code Online (Sandbox Code Playgroud)

上面的宏 $TTL 会将任何条目的 TTL 设置为 14400 秒,除非它被特定条目覆盖。

参考