Sub topic 17
Restricting Access and Hardening the Server
Prerequisites and threat model
This chapter assumes that you can use a Linux shell, edit files, manage systemd services, and configure a firewall. It also assumes that you know whether the server is authoritative, recursive, or both.
A DNS server should answer only the questions it is meant to answer. An open recursive resolver accepts queries from the public internet and can be abused for cache poisoning, information gathering, or reflection attacks. Zone transfers can also expose every record in a private zone unless they are restricted.
Use different exposure rules for different roles:
| Server role | Allowed clients | Important restriction |
|---|---|---|
| Public authoritative server | Internet clients | Disable recursion |
| Internal recursive resolver | Your networks | Refuse all other clients |
| Secondary server | Primary server | Permit transfers only with authentication |
Restrict BIND
For an authoritative-only BIND server, disable recursion and allow transfers only to the known secondary server:
acl "local-admins" {
127.0.0.1;
192.0.2.0/24;
};
options {
directory "/var/cache/bind";
listen-on { 192.0.2.10; };
listen-on-v6 { none; };
recursion no;
allow-query { any; };
allow-transfer { none; };
minimal-responses yes;
};
zone "example.com" {
type primary;
file "/etc/bind/db.example.com";
allow-transfer { 192.0.2.11; };
};listen-on controls the local addresses where BIND accepts requests. recursion no prevents this server from resolving unrelated names for clients. The zone-level allow-transfer overrides the global denial for the approved secondary.
If BIND also provides recursion, replace the broad query policy with an internal ACL and configure allow-recursion explicitly. Keep authoritative public zones separate from internal recursive access when possible.
Restrict Unbound and the network
Unbound should listen only on loopback and trusted LAN addresses:
server:
interface: 127.0.0.1
interface: 192.0.2.10
access-control: 127.0.0.0/8 allow
access-control: 192.0.2.0/24 allow
access-control: 0.0.0.0/0 refuse
hide-identity: yes
hide-version: yes
qname-minimisation: yes
prefetch: yesThe firewall must enforce the same boundary. Permit UDP and TCP port 53 from the intended clients. For a secondary transfer, permit TCP port 53 from the primary only. Do not expose an internal resolver directly to the internet.
Review the request path
Check configuration before reloading, then test both an allowed and a denied client:
sudo named-checkconf
sudo unbound-checkconf
sudo systemctl reload named
sudo systemctl reload unbound
dig @192.0.2.10 example.com SOAStore zone files and keys with ownership and permissions that prevent ordinary users from reading or changing them. Use TSIG keys for zone transfers, keep them out of shell history, and rotate them when administrators or hosts change.
Exercise
Why should an authoritative-only BIND server set recursion no even when it has public DNS records?
Show answer
It should answer only for its authoritative zones. Disabling recursion prevents it from becoming an open resolver for unrelated names.