We all know about open resolvers, this question is kind of for the inverse situation. I have a DNS server that is locked down to certain CIDRs acl trusted {[..]
options {
[..]
allow-query {
// Accept queries from our "trusted" ACL. We will
// allow anyone to query our master zones below.
// This prevents us from becoming a free DNS server
// to the masses.
trusted;
};
This works.
However it doesn't stop infected hosts within the allowed ranges to send spoofed (most commonly type ANY) requests. Those are resolved and the response still sent to the spoofed IP that "requested" it (which is usually the target of the attackers).
How to prevent the DNS server from resolving domains requested outside the trusted ranges? Is that even something bind should be doing?
This isn't a problem you should be trying to solve at the service layer.
These problems are rooted in the design of the network topology sitting in front of you. It is a losing battle to try and address these issues from the server itself.
There are a number of approaches you can take. You may want to combine them.
fail2ban
to dynamically block requesting networks.From your question it appears you have a number of computers infected with botnet software. It is important you identify and cleanse these systems. That is beyond the scope of this question. If your routers support it, consider limiting the IP addresses which can originate requests.
The comments in the configuration excerpt in the question refer to your servers answering authoritatively for some zones. For a scenario where the attacker abuses an authoritative server it would make sense to configure Response Rate Limiting to mitigate this.
In the case of attacks abusing a server with recursion enabled, however, locking down recursion access to your own network in combination with ingress filtering is the best way to stop this. (As suggested by @Andrew-B.)
Regarding BIND specifically it's essential to understand how the different
allow-*
configuration directives interact when you override one of more of them (without that understanding it's not that obvious how, for instance, overridingallow-query
affects other directives such asallow-recursion
).