Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In my DNS server's named.conf I see

    rate-limit {
            responses-per-second 5;
            window 5;
    };

What does this actually mean? And can it cause DNS clients problems? Is this too tight a configuration?

share|improve this question
    
As for "what does it actually mean" I would recommend the relevant section in the manual‌​, also see the same section for the upcoming 9.10 version –  Håkan Lindqvist Mar 30 at 9:20

4 Answers 4

up vote 6 down vote accepted

It limits the number of identical responses a single DNS client can get in a second. The window 5 option allows a burst of 5*5 responses.

"Identical responses" and "single DNS client" are a bit non-obvious terms here, read this for more info: http://ss.vix.su/~vjs/rl-arm.html .

Generally it's a good thing to rate-limit - may help you in case of a DOS attack some day. The defaults should be OK for most cases.

share|improve this answer

You should read the administrator reference manual for BIND 9.9.

Basically, responses-per-second is the number of identical replies that can be sent to one single destination, per second. The definitions are tricky.

A single destination is a block of network addresses, of the size configured in ipv4-prefix-length or ipv6-prefix-length as applicable. So, if the ipv4-prefix-length is 24, and both 192.0.2.1 and 192.0.2.2 are querying the DNS server, they will share this quota and can only send so many queries between the two of them.

Identical replies are replies to queries for a particular RRtype for a particular existent name, or for a nonexistent name. The following queries are all distinct:

IN A example.net.
IN A www.example.net.
IN AAAA example.net.
IN A nonexistent.domain.example.net.

However, all of the following queries are identical (assuming nonexistent.domain.example.net. etc. live up to their names):

IN A nonexistent.domain.example.net.
IN A nonexistent.domain2.example.net.
IN SOA other.nonexistent.domain.example.net.

window complicates things a little more still. It is the number of seconds for which quota can be banked. Multiplying window and responses-per-second gives the maximum by which any quota can be positive, or in more basic terms, the burst capacity.

To give a catch-all example:

You are the nonrecursing, authoritative nameserver for example.net.. Imagine no DNS traffic was seen at all in the past 10 seconds, and the configuration in the question applies globally. The following events happen sequentially:

  1. Host 198.51.100.1 sends 100 queries for IN NS example.net.. 25 will be allowed, and the remaining 75 will be ignored.
  2. Host 198.51.100.1 sends 100 queries for IN A nonexistent.example.net.. 25 will be allowed, and the remaining 75 will be ignored.
  3. Host 198.51.100.1 sends 1 query for IN MX nonexistent-domain.example.net. It will be ignored since the limit for nonexistent domains has been reached.
  4. Host 198.51.100.1 sends 1 query for IN A example.net.. It is allowed.
  5. Hosts 192.0.2.1 through 192.0.2.50 each send a single query for IN NS example.net.. 25 of them get replies and the remaining 25 are ignored; the quota for 198.51.100.0/24 does not apply to these hosts, but they share the quota for 192.0.2.0/24.
  6. One second passes
  7. Hosts 192.0.2.26 through 192.0.2.50 repeat their query IN NS example.net.. 5 of them get replies and the remaining 20 are ignored, since the quota is only replenished by 5 queries per second.
share|improve this answer
iptables -A INPUT -p udp --dport 53 -m recent --set --name dnslimit
iptables -A INPUT -p udp --dport 53 -m recent --update --seconds 60 --hitcount 11 --name dnslimit -j DROP 

IPtables can work just as well. Keeps the traffic out of the service completely if an attack is found.

share|improve this answer
    
awesome! I didn't even think of iptables. But what does that mean in English. I can guess ... if some IP sends 11 or more dns queries block them for 60 seconds, right? –  Red Cricket Mar 22 '13 at 6:44
    
No, the translation is : Accept no more than 11 packets within a timeframe of 60 seconds, drop all other packets. –  drcelus Mar 22 '13 at 7:38
1  
I had a problem, after try to apply your nice solution I had an error like: "iptables: Applying firewall rules: iptables-restore v1.4.7: -c packet counter not numeric Error occurred at line: 17" Line 17 is the first one of yours. I should load some specific module? –  user172544 May 6 '13 at 6:46
    
first line should be as follow: iptables -A INPUT -p udp -m udp --dport 53 -m recent --set --name dnslimit --rsource –  user173406 May 12 '13 at 5:43
2  
I wouldn't go as far as saying say that it "works just as well". This rate limits without any idea if it's actually the same query being spammed or different queries, the latter would much more likely be legitimate traffic. –  Håkan Lindqvist Mar 30 at 9:26

I don't think its a good idea to rate limit, ask yourself : do you rate limit the webserver responses too? Why do you think DNS responses are less important than webserver responses?
And even if you rate limit, that 5 req/sec sounds very low.

share|improve this answer
2  
Ratelimiting webserver responses might nog be such a bad idea in certain cases. But DNS is mostly UDP, which is easily spoofed (unlike http), so rate limiting is necessary prevent you nameservers from being used in amplification or reflection attacks. –  arjarj May 12 '13 at 13:31
    
If he is not an open resolver then i don't think its a good target for reflection/amplification attacks, but you have right. 5 req/sec i still think is too low. –  Sandor Marton May 12 '13 at 13:49
1  
He doesn't specify if it's a recursive or an authoritative server. For an authoritative server rate limiting still is important. Also, it's not just 5 requests per second, it's 5 of the same answers per second, and even corrected if you generate different answers. Generally the 5 requests-per-second setting is fine on bind (because a legitimate server also asks other questions in between). –  arjarj May 12 '13 at 14:17
    
Ok, i checked the docs and as i see rate-limit is a per client setting and not per server. I was under the impression that bind would be limited to a total if 5req/s. Per client 5req/sec is ok. –  Sandor Marton May 12 '13 at 14:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.