curl 和 dnsmasq 的循环

curl 和 dnsmasq 的循环

我已将 dnsmasq 设置为基本配置,指向具有两个 IP 地址的文件。

10.0.0.1 a.b.c
10.0.0.2 a.b.c

当我在 abc 上进行 nslookup 或 dig 时,我看到循环似乎有效(正如我所期望的,因为据我所知,循环是 dnsmasq 中的默认设置)。但是当我curl或ping abc时,我总是得到相同的响应。明显的第一个响应是响应正在被缓存,但据我所知,curl 不会缓存响应,当您对curl 使用 -v 标志时,打印的第一行类似于“缓存丢失”。

所以我想知道的是:我的设置是否做错了什么?是否还有其他地方可能发生缓存?我可以提供确切的文件或更多信息,但我目前有点不明白为什么我没有看到轮换发生。

答案1

Curl使用了getaddrinfo(),它使用了系统缓存机制,详细的过程说明请看下面的答案:

https://stackoverflow.com/a/17938429/3331838

获取,在 no-dns-cache 选项中更详细地描述了这一点

Please note that this option will not affect caching that might be performed by the resolving library or by an external caching layer, such as NSCD. 

If you don’t understand exactly what this option does, you probably won’t need it.

您可能需要做的是强制 ncsd 服务器使请求之间的任何缓存无效

nscd -i hosts

或完全禁用缓存(不确定这可能会导致什么问题),请参阅以下答案以获取有关此问题的详细信息

https://unix.stackexchange.com/a/34665/191614

相关内容