2

I am looking for a way to automatically refresh entries in my cache if it expires.

For example, example.com has a TTL of 60, i would like to automatically refresh it if it expires so that when users query example.com a fresh version is already in the cache.

Is this possible within bind?

Thanks!

Susan
  • 43
  • 2
  • 6
  • I hate to ask the question... but why would you need to pre-cache DNS info? When a user asks... it gets cached. – TheCompWiz Sep 06 '13 at 14:14

2 Answers2

1

No, there isn't. The cache is designed to automatically "record" entries when they are accessed for the first time for faster access later. There's no performance gain to "pre-caching" entries like you're describing.

Nathan C
  • 15,059
  • 4
  • 43
  • 62
  • While it is not practical to do this on large scale servers i think it does offer gains for small or personal servers because most people access the same domains every day and these records could as well be kept fresh in the cache. – Susan Sep 06 '13 at 13:55
  • There's no sense in precaching as the first "hit" will cache the entry up to the TTL. I suppose you could issue a DNS query shortly after the TTL expires to re-cache, but Bind doesn't have this function. You might as well set a longer TTL. – Nathan C Sep 06 '13 at 13:57
  • Thanks, then i will have to write my own tool to do this. Yes but the first hit takes time and some sites which i do not control have a very very short TTL. – Susan Sep 06 '13 at 13:59
  • 1
    So you want to cache for longer than the authoritative TTL? That's all kinds of wrong. – Tom O'Connor Sep 06 '13 at 14:05
  • @TomO'Connor not really... it sounds like she's trying to pre-populate the cache. As the TTL is valid... and not being overridden... it's not really wrong. I honestly can't see the logic in doing this... as it will be cached the first time someone asks... and will be valid for all users that query against it... but /meh – TheCompWiz Sep 06 '13 at 14:15
  • The logic is that DNS lookups must take her an inordinate amount of time. Looksups from my network take about 20-50ms. If you were on dialup from Romania, the lookup time might a noticeable amount. BIND does not have a prefetch feature, but Unbound does (others might too). – Chris S Sep 06 '13 at 14:25
1

BIND supports a technique called prefetch. Using prefetch BIND will automatically refresh entries that are about to expire. The following is the syntax of prefetch.

 sudo vim /etc/bind/named.conf.options
 ...
 options {
 ...
 prefetch 2 9;
};
...

As you can see this has two numbers, the trigger (here 2), and the eligibility (here 9). This tells BIND to refresh DNS entries for all entries whose initial TTL was greater than 9 seconds, if the remaining TTL falls below 2 seconds. Thus it will not blindly refresh all entries, instead it will only monitor entries which have an initial TTL greater than eligibility, and once the remaining TTL for these entries falls below the trigger value it will refresh them. The values of eligibility, and trigger are in seconds.

So, let's say example.com has a TTL of 60 seconds (i.e. TTL when the record was fetched), I want to ensure that if the remaining TTL falls below 10 seconds, the entry should be refreshed. The following will be my prefetch option in the config file.

prefetch 10 60

Further reading: https://kb.isc.org/article/AA-01122/0

Sahil Singh
  • 113
  • 5