$ run as a normal user# run as root (or with sudo)
Know it before you install
An authoritative server answers for zones it owns (from zone files). A recursive server finds answers for anyone's names on the internet and caches them. Keep the two roles apart on internet-facing servers — an open resolver is abused for DDoS attacks.
| Item | RHEL / Rocky / Alma | Ubuntu / Debian |
|---|---|---|
| Packages | bind, bind-utils | bind9, bind9-utils, bind9-dnsutils |
| Service | named.service | named.service (bind9 is an alias) |
| Main config | /etc/named.conf | /etc/bind/named.conf (+ named.conf.options, named.conf.local) |
| Zone files | /var/named/ | /etc/bind/ or /var/lib/bind/ |
| Tools | named-checkconf, named-checkzone, rndc, dig | the same |
| Ports | 53/udp and 53/tcp | the same |
Install on RHEL, Rocky, Alma and Fedora
dnf -y install bind bind-utils
systemctl enable --now named
firewall-cmd --permanent --add-service=dns
firewall-cmd --reloadInstall on Ubuntu and Debian
apt-get update
apt-get install -y bind9 bind9-utils bind9-dnsutils
systemctl enable --now named
ufw allow 53Watch out
On Ubuntu, systemd-resolved listens on 127.0.0.53:53. That is fine for BIND on the server's own IPs; if you need BIND on 127.0.0.1 too, set DNSStubListener=no in /etc/systemd/resolved.conf and restart systemd-resolved.
First configuration: a safe resolver
Recursion only for your networks, DNSSEC validation on, version hidden (RHEL: in /etc/named.conf; Ubuntu: in named.conf.options):
acl "trusted" {
127.0.0.1;
10.0.0.0/8;
192.168.0.0/16;
};
options {
directory "/var/named";
listen-on port 53 { 127.0.0.1; 10.0.0.53; };
listen-on-v6 port 53 { ::1; };
allow-query { trusted; };
allow-recursion { trusted; };
allow-transfer { none; };
recursion yes;
dnssec-validation auto;
version "not available";
forwarders { 1.1.1.1; 9.9.9.9; };
forward first;
};| Setting | Why |
|---|---|
allow-recursion { trusted; } | Only your networks may use the resolver — no open resolver. |
allow-transfer { none; } | Nobody can download your zones, except secondaries you allow per zone. |
dnssec-validation auto | Reject forged answers for signed zones. |
listen-on | Only the IPs that should answer. |
forwarders (optional) | Send queries to upstream resolvers; without it BIND resolves from the root servers itself. |
named-checkconf
systemctl reload named
dig @10.0.0.53 www.redhat.com +shortAn authoritative zone
Add the zones to the config (RHEL: /etc/named.conf; Ubuntu: named.conf.local):
zone "corp.example.com" IN {
type primary;
file "corp.example.com.zone";
allow-transfer { key "xfer-key"; };
notify yes;
};
zone "1.0.10.in-addr.arpa" IN {
type primary;
file "10.0.1.rev";
};$TTL 3600
@ IN SOA ns1.corp.example.com. hostmaster.corp.example.com. (
2026111701 ; serial YYYYMMDDNN
3600 ; refresh
900 ; retry
1209600 ; expire
300 ) ; negative cache TTL
IN NS ns1.corp.example.com.
IN NS ns2.corp.example.com.
IN MX 10 mail.corp.example.com.
ns1 IN A 10.0.0.53
ns2 IN A 10.0.0.54
web1 IN A 10.0.1.11
db1 IN A 10.0.1.21
mail IN A 10.0.1.25
www IN CNAME web1$TTL 3600
@ IN SOA ns1.corp.example.com. hostmaster.corp.example.com. ( 2026111701 3600 900 1209600 300 )
IN NS ns1.corp.example.com.
11 IN PTR web1.corp.example.com.
21 IN PTR db1.corp.example.com.Check, fix rights and SELinux (RHEL), reload:
named-checkzone corp.example.com /var/named/corp.example.com.zone
zone corp.example.com/IN: loaded serial 2026111701
OK
named-checkzone 1.0.10.in-addr.arpa /var/named/10.0.1.rev
chown root:named /var/named/*.zone /var/named/*.rev
restorecon -Rv /var/named
rndc reload
dig @10.0.0.53 web1.corp.example.com +short
10.0.1.11
dig @10.0.0.53 -x 10.0.1.11 +short
web1.corp.example.com.Remember
Increase the serial at every change of a zone file, or the secondaries will not take the change.
A secondary server with TSIG
Make a shared key on the primary, copy the same key block to the secondary:
tsig-keygen -a hmac-sha256 xfer-key > /etc/named/xfer-key.conf
chown root:named /etc/named/xfer-key.conf && chmod 640 /etc/named/xfer-key.confInclude it on both servers (include "/etc/named/xfer-key.conf";). On the secondary:
server 10.0.0.53 { keys { xfer-key; }; };
zone "corp.example.com" IN {
type secondary;
primaries { 10.0.0.53 key xfer-key; };
file "slaves/corp.example.com.zone";
};Daily use: the commands and the real uses
rndc status
rndc reload corp.example.com
rndc flush
rndc dumpdb -cache
rndc querylog on
journalctl -u named -f
dig @10.0.0.53 corp.example.com SOA +short
dig @10.0.0.53 corp.example.com AXFR
dig +trace www.example.orgReal uses at work:
- Internal DNS for servers and apps (
corp.example.com), with reverse zones for logs and tools. - A caching resolver for offices and data centers (with DNSSEC validation).
- Split DNS (different answers inside and outside) with
viewblocks.
Make it safe
Security checklist:
- No open resolver:
allow-recursiononly for trusted networks. allow-transferonly with TSIG keys to your secondaries.dnssec-validation auto; sign your public zones (DNSSEC) when possible.- Run authoritative and recursive roles on different servers for internet-facing DNS.
- Keep BIND updated (security releases are frequent); hide the version; rate limiting (
rate-limitblock) on authoritative servers. - Zone files and keys with tight rights; SELinux on.
Update and remove
dnf -y upgrade bind bind-utils
apt-get install --only-upgrade -y bind9
named-checkconf && systemctl restart named
dnf -y remove bindFix common problems
| Problem | Cause | Fix |
|---|---|---|
status: REFUSED | The client is not in allow-query/allow-recursion. | Add its network to the trusted ACL. |
status: SERVFAIL for external names | DNSSEC validation failed, no internet/forwarders, or wrong time. | Check time (chrony); dig +cd to test without validation; check forwarders. |
| Zone does not load | Syntax error, missing dot at the end of a name, wrong file rights. | named-checkzone; journalctl -u named; owner root:named, restorecon. |
| Secondary keeps the old data | Serial not increased. | Increase the serial; rndc reload; check notify. |
Names resolve to web1.corp.example.com.corp.example.com | Missing trailing dot on a full name. | Write full names with a . at the end. |
| BIND will not start on Ubuntu: port in use | systemd-resolved stub listener. | Listen on specific IPs, or DNSStubListener=no. |
Next steps
- Quick how-tos: Check the DNS records of a domain, Run your own DNS zone.
- Command page: rndc, Command page: dig, Command page: host.
- At work: BIND — DNS server.
- DNS on clients: RHCSA — DNS and /etc/hosts, RH124 — Check names and DNS.
- The right time for DNSSEC: chrony.
1Why must allow-recursion be limited to your own networks?
An open resolver is used by attackers for DNS amplification DDoS attacks.
2You changed a zone file, but the secondary still shows the old IP. Why?
The SOA serial was not increased, so the secondary did not transfer the zone.