Sub topic 6
Testing DNS with `dig` and Configuration Checkers
This chapter assumes you can use a Linux shell, edit configuration files, manage systemd services, and distinguish UDP from TCP. It also assumes BIND or Unbound is installed on a test server. Run tests locally before allowing clients to use the service.
A DNS test has several layers
A successful DNS test does not only mean that a process is listening on port 53. Check the layers in this order:
- The service is running and listening on the expected address.
- The configuration has valid syntax.
- The server answers the question you asked.
- The answer has the expected authority, flags, records, and TTL.
- A remote client can reach the server through the firewall.
sudo systemctl status named
sudo systemctl status unbound
sudo ss -lntup | grep ':53 'The service name differs by distribution. On some systems, BIND uses named; on others, it may use a distribution-specific unit name.
Validate before reloading
Use the checker that matches the software:
sudo named-checkconf
sudo named-checkzone example.com /etc/bind/db.example.com
sudo unbound-checkconfnamed-checkconf checks BIND configuration syntax. named-checkzone checks a specific zone file, including record format and common SOA errors. unbound-checkconf checks Unbound configuration syntax.
A checker does not prove that the server has the correct IP address, firewall rules, delegation, or records. Treat a successful check as permission to continue testing, not as proof that DNS works.
Reload only after validation:
sudo rndc reload example.com
sudo unbound-control reloadQuery with `dig`
dig displays the response and metadata. The @ argument selects the server, so the test does not depend on the system resolver.
dig @127.0.0.1 www.example.com A
dig @127.0.0.1 example.com SOA +short
dig @127.0.0.1 -x 192.0.2.20
dig @127.0.0.1 www.example.com A +norecurse
dig @127.0.0.1 example.org A +dnssecThe status should normally be NOERROR. NXDOMAIN means the name does not exist. SERVFAIL usually indicates a server-side failure, such as failed recursion or DNSSEC validation. REFUSED often indicates an access-control rule.
The aa flag means an authoritative answer. The ra flag means recursion is available. The ad flag indicates that a validating resolver authenticated the DNSSEC result. +short suppresses most diagnostic detail, while +norecurse tests whether the server answers from its authoritative data or cache without starting recursion.
Troubleshoot from evidence
Inspect recent service messages after a failed check or reload:
sudo journalctl -u named --since "10 minutes ago"
sudo journalctl -u unbound --since "10 minutes ago"Compare local and remote results. If local queries succeed but remote queries fail, inspect listen settings, access controls, and UDP and TCP firewall rules. DNS commonly uses UDP, but larger responses and some operations require TCP.
Exercise
A query to dig @127.0.0.1 internal.example A returns REFUSED, while the configuration checker reports no errors. What should you inspect first?
Show answer
Inspect the server's access-control rules and listening addresses. Syntax validation does not mean that the client address is permitted to query the server.