Skip to content

Security Operations / Network monitoring · Step 3 of 6

Lesson: DNS LogsSwitch
← Security Operations

Security investigations

DNS Logs

Read DNS queries and answers to spot problems, and know what they do not prove.

DNS turns names into addresses and other data. Logs of queries show which names devices asked about, which is useful for both troubleshooting and security. They are also sensitive, so limit who reads them.

What a record holds

A useful DNS log entry has the time, the client, the name, the query type (such as A, AAAA, MX or TXT) and the response code.

  • NOERROR: the query succeeded. The answer can still be empty.
  • NXDOMAIN: the name does not exist.
  • SERVFAIL: the server could not complete the query.
  • REFUSED: the server declined it.
$ dig example.invalid
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 4821

.invalid is reserved so that it never resolves. Output is shortened.

Where to collect

Log at the resolver your clients use. Each server has its own format. With dnsmasq, the log-queries option writes lines like these:

query[A] example.com from 10.0.0.5
forwarded example.com to 192.0.2.53
reply example.com is 192.0.2.10

Times and prefixes are trimmed. Cached answers appear as cached instead of being forwarded.

Clients that use another resolver, or encrypted DNS such as DNS over HTTPS to an outside service, will not show up in your resolver's log.

Patterns worth a look

  • Many NXDOMAIN answers from one host.
  • Very long, random looking names under one domain.
  • Regular queries at fixed intervals.
  • Unusual volumes of TXT queries.

These can come from malware, but also from antivirus lookups, content delivery networks, or a mistyped setting. Check what process on the client is asking. A query shows that a name was looked up. It does not show that a person visited a site, or that any connection followed. Match with flow or proxy records to learn more.

Try it

Run dig example.com and dig example.com AAAA, and find the status and answer section in each. The dig command comes in the bind9-dnsutils package on Debian and Ubuntu, and bind-utils on Fedora and RHEL.

Check your understanding

DNS Logs

All 3 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.