配置 Windows DNS 解析器缓存

发布于 2024-07-14 18:11:14 字数 1026 浏览 5 评论 0原文

请注意,我说的是客户端 DNS 解析器缓存。 此消息与 Windows DNS 服务器无关。

我有一个 C# 程序,可以执行大量 DNS 解析。 因为 HTTPWebRequest 组件不允许我更改主机标头,所以我无法创建自己的内部 DNS 缓存。 所以我必须依赖 Windows DNS 缓存,它似乎无法改变。

有一篇相当不错的 TechNet 文章< /a> 关于 Windows Server 2003 中的 DNS 缓存注册表设置,但我无法证明设置它们会起到任何作用。 我通过谷歌搜索找到的所有其他页面要么引用该页面,要么解释它,有时是错误的。

Windows 的 ipconfig 命令有一个 /displaydns 开关,它将输出缓存的内容。 据我所知,这是确定 DNS 缓存大小的唯一方法。 在我对具有 2 GB 内存的 32 位 Windows XP 机器上进行的实验中,无论我将 DNS 缓存注册表值设置为多少,我最终都会在缓存中得到 30 到 40 个项目 - 即使在进行了数千次 DNS 解析之后也是如此。 在我的具有 16 GB 内存的 64 位 Windows 2008 计算机上,我总是在缓存中获取 270 到 300 个项目。

我很困惑。 我不知道答案是什么,但我认为是以下情况之一:

  1. 无法更改 DNS 解析器缓存的大小。
  2. 这是可能的,但文档是错误的。
  3. 该文档就目前而言是正确的,但并不完整。
  4. 该文档是正确且完整的,但我太笨了,无法理解它。
  5. 记录的注册表项实际上更改了缓存的大小,但 ipconfig 没有向我显示缓存中的所有条目。

谁能告诉我是否可以在 Windows XP、Vista 或 Server 2008 中配置 DNS 解析器缓存的大小?

Note that I'm talking about the client DNS resolver cache. This message is not concerned with the Windows DNS Server.

I have a C# program that does a lot of DNS resolutions. Because the HTTPWebRequest component won't let me change the Host header, I can't create my own internal DNS cache. So I have to depend on the Windows DNS cache, which doesn't appear amenable to change.

There's a reasonably good TechNet article about the DNS cache Registry settings in Windows Server 2003, but I haven't been able to prove that setting them does anything. All the other pages I found through a Google search either reference that page, or paraphrase it, sometimes incorrectly.

Windows' ipconfig command has a /displaydns switch that will output the contents of the cache. To my knowledge, that's the only way to determine the size of the DNS cache. In my experiments on a 32 bit Windows XP box with 2 GB of memory, no matter what I set the DNS cache registry values to, I always end up with between 30 and 40 items in the cache--even after doing thousands of DNS resolutions. On my 64-bit Windows 2008 machine with 16 GB of memory, I always get between 270 and 300 items in the cache.

I'm stumped. I don't know what the answer is, but I figure one of the following is the case:

  1. It's not possible to change the size of the DNS resolver cache.
  2. It is possible, but the documentation is wrong.
  3. The documentation is correct as far as it goes, but it’s incomplete.
  4. The documentation is correct and complete, but I’m too dumb to make sense of it.
  5. The documented registry entries actually changed the size of the cache, but ipconfig isn’t showing me all the entries that are in the cache.

Can anybody tell me if it's possible to configure the size of the DNS resolver cache in Windows XP, Vista, or Server 2008?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

混浊又暗下来 2024-07-21 18:11:14

通过这些设置,在网络上仅几分钟后,我就看到 1517 个缓存条目:

REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters]
"QueryIpMatching"=dword:00000001
"NegativeCacheTime"=dword:00000000
"NegativeSOACacheTime"=dword:00000000
"CacheHashTableBucketSize"=dword:00000001
"CacheHashTableSize"=dword:00000180
"MaxCacheEntryTtlLimit"=dword:00000e10
"MaxSOACacheEntryTtlLimit"=dword:0000012c

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]
“QueryIpMatching”=dword:00000001

With these settings, after just a few minutes on the web, I am seeing 1517 cached entries:

REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters]
"QueryIpMatching"=dword:00000001
"NegativeCacheTime"=dword:00000000
"NegativeSOACacheTime"=dword:00000000
"CacheHashTableBucketSize"=dword:00000001
"CacheHashTableSize"=dword:00000180
"MaxCacheEntryTtlLimit"=dword:00000e10
"MaxSOACacheEntryTtlLimit"=dword:0000012c

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]
"QueryIpMatching"=dword:00000001

梦在夏天 2024-07-21 18:11:14

有一个程序“便携式 DNS 缓存”,您可以使用它来查看 DNS 缓存、监视 DNS 解析器的活动,并查看通过缓存解析的查询以及转发到 DNS 服务器的查询。 在其设置中,您可以配置缓存中的最大项目数。 尽管如此,它似乎强制所有项目保留在缓存中,直到您单击“清除缓存”按钮或达到缓存限制。

There is a program "Portable DNS Cache" that you can use to view the DNS cache, monitor activity of DNS resolver, and see queries resolved via cache and those forwarded to DNS server. In its settings, you can configure the maximum number of items in the cache. Although, it seems that it forces all items to stay in cache until you click "Clear Cache" button or cache limit is reached.

听风吹 2024-07-21 18:11:14

默认情况下,缓存的最小 TTL 为 1 天,我已经尝试过它,但默认情况下我相信默认情况下注册表项不存在。

这是您要查找的键,至少在 XP 中是这样的:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DNSCache\Parameters

您需要添加一个 DWORD MaxCacheTtl - 这将更改存储在解析器缓存中的最小 TTL。

由于它默认为 86,400(值以秒为单位,默认 = 1 天),因此任何短于此的内容都不会被缓存。 如果您将其降低到 300,您会看到更多的内容被缓存在客户端上。

By default the minimum TTL for cache is 1 day, I've toyed with it but by default I believe the registry entry isn't there by default.

This is the key you're looking for, at least in XP:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DNSCache\Parameters

You need to add a DWORD MaxCacheTtl - This will change the minimum TTL to store in the resolver cache.

Since it defaults to 86,400 (value is in seconds, default = 1 day), anything shorter than this simply isn't cached. If you lowered it to say 300, you'd see tons more getting cached on the client.

我很坚强 2024-07-21 18:11:14

您可以使用的一种技巧是将条目添加到 Windows 上的主机文件中,这样就不会对该文件中的所有条目进行 DNS 查询。 您可以定期再次查询以验证条目。

A hack you can use is to add entries to the hosts file on Windows, which would make it not make DNS queries for all the entries in the file. You can periodically then query again to verify entries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文