<div dir="auto">Simon,<div dir="auto"><br></div><div dir="auto">Hosts in domain .consul are resolved by DNS servers forwarding requests to a consul clusters.  I also have hard coded direct consul server records for .consul in dnsmasq config.  Nothing in /etc/hosts . Consul returns records with  TTL 0 .  I perhaps wrongly thought it meant they are not cached.  That is why I added ttl-min 5s.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 17, 2020, 10:46 AM Simon Kelley <<a href="mailto:simon@thekelleys.org.uk" target="_blank" rel="noreferrer">simon@thekelleys.org.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 17/03/2020 01:31, Sasha Litvak wrote:<br>
> I couldn't find a specific answer anywhere so hopefully someone has a<br>
> clue on this list<br>
> <br>
> We are using dnsmasq on our servers as a caching dns solution.<br>
> <br>
> Most of our domains are resolved by a wildcard record like this<br>
> <br>
> $TTL 3600       ; 1 hour<br>
>                         A       10.10.10.23<br>
> $ORIGIN <a href="http://example.net" rel="noreferrer noreferrer noreferrer" target="_blank">example.net</a>.<br>
> *                       CNAME   excontainers<br>
> excontainers    CNAME   exservice.service.consul<br>
> <br>
> dnsmasq handles resolution of .consul domain directly but the DNS<br>
> server itself also forwards .consul to consul servers.<br>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
<br>
<br>
Can you elaborate? How does dnsmasq handle the resolution of the .consul<br>
domain? If you have something like<br>
<br>
10.0.48.13 exservice.service.consul<br>
<br>
in /etc/hosts<br>
<br>
then that defines, effectively, an immortal record for<br>
exservice.service.consul, so a CNAME chain of two records, each with a<br>
TTL of one hour, would result in that answer being returned for an hour.<br>
<br>
> <br>
> I added min-ttl 5s to decrease the number of queries to consul<br>
> <br>
> So when I do dig <a href="http://foo.example.net" rel="noreferrer noreferrer noreferrer" target="_blank">foo.example.net</a>  @<a href="http://127.0.0.1" rel="noreferrer noreferrer noreferrer" target="_blank">127.0.0.1</a> I get<br>
> <br>
> <a href="http://foo.example.net" rel="noreferrer noreferrer noreferrer" target="_blank">foo.example.net</a>. 3600 IN CNAME <a href="http://excontainers.example.net" rel="noreferrer noreferrer noreferrer" target="_blank">excontainers.example.net</a>.<br>
> <a href="http://excontainers.example.net" rel="noreferrer noreferrer noreferrer" target="_blank">excontainers.example.net</a>. 3600 IN CNAME exservice.service.consul.<br>
> exservice.service.consul. 5 IN A 10.0.48.13<br>
<br>
This might be misleading: is you do that query to dnsmasq with a clean<br>
cache, it will forward the query upstream, and return the complete<br>
result it gets, including the A record with a 5s TTL, but further<br>
queries from the cache would return a 0 (infinite) TTL for the A record<br>
of it's defined locally.<br>
<br>
The fix for this is to define the .consul A record using --host-record,<br>
which allows you to specify the 5s TTL.<br>
<br>
<br>
<br>
> <br>
> Now we often need to migrate subdomains by pointing them to a<br>
> different consul cluster.  So our script uses nsupdate and creates a<br>
> dynamic DNS record resulting in this reply<br>
> <br>
> <a href="http://foo.example.net" rel="noreferrer noreferrer noreferrer" target="_blank">foo.example.net</a>. 60 IN CNAME  exservice2.service.consul.<br>
>  exservice2.service.consul. 5 IN A 10.0.48.35<br>
> <br>
> So we have a record that is more explicit and it takes precedence over<br>
> wild card.   On servers with little traffic, domain switch happens<br>
> within a few seconds, but on the main busy server with 100s of queries<br>
> a second, it takes an hour for dnsmasq to change its cache.  We see<br>
> dnsmasq sending requests to the DNS server getting correct new records<br>
> but still sending the old cached records to a client.<br>
> <br>
> When we are going back from distinct to default wild card (removing<br>
> distinct record in DNS) cache change happens almost immediately (a<br>
> couple of seconds) regardless of how busy the server is.<br>
> <br>
> Sorry for the long description but I would like to find out a reason<br>
> why during switching from wild card to more explicit record dnsmasq<br>
> cache update takes such a long time.<br>
> <br>
<br>
I'm guessing at exactly what's going on here: more details would be<br>
useful, but if I guessed right, that's the solution.<br>
<br>
<br>
Simon.<br>
<br>
<br>
_______________________________________________<br>
Dnsmasq-discuss mailing list<br>
<a href="mailto:Dnsmasq-discuss@lists.thekelleys.org.uk" rel="noreferrer noreferrer" target="_blank">Dnsmasq-discuss@lists.thekelleys.org.uk</a><br>
<a href="http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss" rel="noreferrer noreferrer noreferrer" target="_blank">http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss</a><br>
</blockquote></div>