Taking it for granted that DNS blacklisting is not a way to stop someone from getting to a site if they really want to, but useful for dealing with malicious software and casual attempts to get to a bad website...
Response Policy Zones (RPZ)
RPZ allows you to create a zone file that defines response rewriting rules. These were implemented in version 9.8.1.
Let's say you want to block badrecord.example.com.
, which has an IP address of 198.51.100.1
. The real IP doesn't matter here, but providing one to help reinforce what happens.
options {
# Snip.
response-policy { zone "mypolicy"; };
};
zone "mypolicy" {
type master;
file "mypolicy.zone";
allow-query { none; };
};
The zone file would look like:
$TTL 1H
@ SOA LOCALHOST. doesnt.really.matter.example.org. (1 1h 15m 30d 2h)
; NS required for zone syntax reasons, but ignored
NS LOCALHOST.
; CNAME bad reply to a DNS record that isn't in this file
badrecord.example.com. CNAME mywalledgarden.example.edu.
; replace bad reply with fixed IP address
badrecord2.example.com. A 203.0.113.1
; rewrite the top of a bad domain, as well as all records immediately
; beneath the apex. (i.e. not further than one level deep)
example.net. A 203.0.113.1
*.example.net. A 203.0.113.1
Observations:
- "mypolicy" is an actual DNS zone. You can use zone transfers to distribute it around your environment and control the data from a single server.
- Users are not allowed to directly query the zone due to the
allow-query
rule.
- These rules do not block queries, but any replies to a query that would normally contain the bad data will be rewritten. A side effect of this is that a request for a non-existent record will return
NXDOMAIN
properly. You will only modify the response if it was possible for a client to obtain a response containing bad data.
- The usual rules for DNS wildcard matching apply.
These are not the only rewrites that you can perform. For full the syntax and potential applications, I recommend that you consult the BIND ARM.
You may find some guides on the internet that suggest things such as creating a root (.
) zone, or creating one zone for every domain you need to block. Don't do that. It's an older, kludgy way of doing things that DNS admins resorted to for lack of better options. If RPZ is an option and it covers your needs, use it. If you are not authoritative for the domain, don't configure yourself to be authoritative for it.