Sub topic 18
Logging, rndc, unbound-control and troubleshooting
This chapter assumes you have a working BIND or Unbound server from the earlier chapters. You should be comfortable with dig, systemctl and journalctl, and with reading a zone file. Here you will turn on useful logs, control running daemons without restarting them, and follow a repeatable method for finding faults.
Where the logs go
Both servers write to different places by default.
| Server | Default destination | Where to look |
|---|---|---|
| BIND | syslog, daemon facility | `journalctl -u named` (RHEL) or `journalctl -u bind9` (Debian/Ubuntu) |
| Unbound | syslog, or a file if `logfile:` is set | `journalctl -u unbound` |
On a systemd host the journal is the first place to look. Startup failures such as a syntax error, a missing file or a port 53 conflict appear there before any logging you configure yourself takes effect.
Logging in BIND
BIND's logging statement connects categories (what is logged) to channels (where it goes). The following fragment sends general messages, zone transfers and DNSSEC messages to a rotating file. It writes queries to a separate file and silences lame-server noise.
logging {
channel default_file {
file "/var/log/named/default.log" versions 3 size 5m;
severity info;
print-time yes;
print-severity yes;
print-category yes;
};
channel query_file {
file "/var/log/named/queries.log" versions 5 size 20m;
severity info;
print-time yes;
};
category default { default_file; };
category xfer-in { default_file; };
category xfer-out { default_file; };
category notify { default_file; };
category dnssec { default_file; };
category queries { query_file; };
category lame-servers { null; };
};Create the directory first and give it to the account that runs named:
sudo install -d -o bind -g bind -m 750 /var/log/named
sudo named-checkconf && sudo rndc reconfigThe account is bind on Debian and Ubuntu and named on the RHEL family. On Ubuntu, AppArmor also restricts where named may write. If the file never appears, check journalctl for a permission error and add the path to the local AppArmor profile.
Query logging is a switch, not a default
The queries category produces one line per request, which is heavy on a busy resolver and records client addresses. Turn it on only while you investigate:
sudo rndc querylog on
sudo rndc querylog offrndc querylog toggles the setting at runtime without editing the configuration.
Logging in Unbound
Unbound's logging is set in the server: block. Verbosity runs from 0 to 5, and each step adds detail.
server:
use-syslog: yes
verbosity: 1
log-queries: no
log-replies: no
log-servfail: yeslog-servfail: yes is useful in production because it records why a lookup failed, for example a DNSSEC validation error, without logging every query. For short investigations, raise the level on the running daemon with unbound-control verbosity 3 and set it back afterwards. Level 4 and above is very noisy.
Controlling BIND with rndc
rndc talks to named over a control channel on 127.0.0.1:953 and authenticates with a shared key. Distribution packages generate the key for you. These commands cover most routine work:
sudo rndc status
sudo rndc reload example.com
sudo rndc reconfig
sudo rndc zonestatus example.com
sudo rndc retransfer example.com
sudo rndc notify example.com
sudo rndc flush
sudo rndc flushname www.example.com
sudo rndc dumpdb -cacheThe differences matter:
reloadwith no argument reloads the configuration and all zones. With a zone name it reloads only that zone.reconfigreloads the configuration and picks up new zones, but it does not reload existing zone files that changed.zonestatusprints the loaded serial, the zone type and the next refresh time.retransfer(run on a secondary) forces a full transfer from the primary.dumpdb -cachewrites the cache tonamed_dump.dbin the working directory, so you can see what the resolver actually holds.
Controlling Unbound with unbound-control
unbound-control needs the remote control feature enabled. On many packages this is already on. If not, add the following and generate certificates:
remote-control:
control-enable: yes
control-interface: 127.0.0.1sudo unbound-control-setup
sudo systemctl restart unbound
sudo unbound-control statusCommon commands:
sudo unbound-control reload
sudo unbound-control flush www.example.com
sudo unbound-control flush_zone example.com
sudo unbound-control dump_cache > /tmp/unbound-cache.txt
sudo unbound-control list_local_data
sudo unbound-control stats_noreset
sudo unbound-control verbosity 3stats_noreset prints counters such as cache hits, cache misses and the number of queries answered with each response code. stats prints the same counters and then resets them. Use stats_noreset when you only want to look.
Keep the control interface on loopback or a Unix socket. Anyone who reaches an unprotected control port can flush caches and change settings.
A method for troubleshooting
Start from the symptom in the response and work inward. Always test against the server directly with @address, so the client's own resolver settings are out of the picture.
Symptom table
| Symptom | Likely cause | First check | Column |
|---|---|---|---|
| Timeout | Daemon down, wrong `listen-on` or `interface`, firewall | `ss -lntup \ | grep ':53 '`, firewall rules |
| `REFUSED` | Client address not allowed, or recursion disabled | `allow-query`, `allow-recursion`, `access-control` | |
| `SERVFAIL` on one name | Broken DNSSEC, dead upstream, zone failed to load | `dig +cd`, then the logs | |
| `SERVFAIL` on your zone | Zone file error, so BIND did not load it | `named-checkzone`, `rndc zonestatus` | |
| `NXDOMAIN` for a name you added | Missing trailing dot, typo, or the zone was not reloaded | Zone file, `rndc reload` | |
| Old data after an edit | Serial not increased, or a cached answer | `dig SOA +short`, `rndc flush` | |
| Secondary stays stale | Transfer blocked, TSIG mismatch or wrong serial | `xfer-in` logs, `rndc retransfer` |
Isolating DNSSEC failures
If a name fails with SERVFAIL but works when you disable checking, the data is likely not valid:
dig @127.0.0.1 www.example.org A
dig @127.0.0.1 www.example.org A +cd+cd sets the "checking disabled" bit. If the second query returns an answer, the problem is DNSSEC. Common causes are expired signatures at the zone owner, a DS record that does not match the zone's key, or a server clock that is wrong. Check the clock with timedatectl before anything else, because a skewed clock makes valid signatures look expired.
Following the delegation
When your server returns data that differs from what other servers return, walk the delegation from the root:
dig www.example.com +trace
dig @ns1.example.com www.example.com A +norecurseThe first command shows which servers the delegation leads to. The second asks the authoritative server directly. If the two disagree, the parent zone points to different name servers than you expect.
Transfers and large answers
DNS uses UDP by default and switches to TCP for large answers and all zone transfers. A firewall that allows only UDP 53 produces strange partial failures. Small answers work and large ones, or transfers, time out. Test TCP explicitly:
dig @192.0.2.10 example.com SOA +tcp
dig @192.0.2.10 example.com AXFR -k transfer-key.confThe second command only succeeds from an address and key that allow-transfer permits, which makes it a good test of your access control. A REFUSED or NOTAUTH result from an unauthorised host is the correct behaviour.
A repeatable checklist
- Run the checkers:
named-checkconf,named-checkzone,unbound-checkconf. - Read the last lines of the journal for the service.
- Query the server directly with
dig @addressand read the status, flags andANSWERsection. - Compare the serial on the primary and the secondary with
dig SOA +short. - Use
+cdand+traceto separate validation faults from delegation faults. - Turn on extra logging, reproduce once, and turn it off again.
Exercise
A user reports that app.example.net fails on your Unbound resolver with SERVFAIL, but a public resolver answers. Which two dig queries and which Unbound setting help you decide whether DNSSEC validation is the cause?
Show answer
Run dig @127.0.0.1 app.example.net A and then dig @127.0.0.1 app.example.net A +cd. If only the +cd query returns an answer, validation is failing. Set log-servfail: yes (or raise verbosity temporarily with unbound-control verbosity 3) to see the validation error in the log. Also check the server's clock, since a wrong date makes valid signatures look expired.
Exercise
You edited db.example.com on the primary but forgot to increase the serial, then ran rndc reload example.com. The primary now serves the new data. Why does the secondary still serve the old data, and how do you correct it?
Show answer
The secondary compares the SOA serial with its own copy and only transfers when the primary's serial is higher. Because the serial did not change, it sees no update. Increase the serial (for example to 2026112802), run named-checkzone, then rndc reload example.com. The primary sends NOTIFY and the secondary transfers. If you need to force it, run rndc retransfer example.com on the secondary.