Join our Newsletter — 33% off our NHI Course
Home› Guides› DNS Logging and Detection Guide: Query Logs for…
Guide Network Security

DNS Logging and Detection Guide: Query Logs for C2, DGA and Tunnelling Detection

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 27 October 2026 13 min read
On this page

Almost every compromised host looks up a name before it talks to its controller, yet many organisations either do not log DNS queries at all or log them somewhere no detection ever runs. DNS query logs record which client asked for which name, of which record type, and what came back. That makes them one of the cheapest and broadest detection sources for command and control over DNS, domain generation algorithms (DGAs), DNS tunnelling and lookups of known bad domains. This guide covers where to collect DNS logs (resolvers, Windows DNS Server, endpoints, cloud resolvers and network sensors), which fields matter, detection logic for the main techniques, how to cope with encrypted DNS and volume, and how to measure coverage. It is for detection engineers and SOC teams. For hardening DNS itself, see the DNS Security Guide.

Key takeaways

  • Log at the resolver your clients actually use, then add endpoint DNS events to recover the process name, because a resolver log alone shows the forwarding server, not the infected machine, in many designs.
  • Record the answer, not only the question. Response code, answer data and TTL are what separate a DGA's burst of NXDOMAIN responses or a fast flux domain from normal traffic.
  • Four detections cover most of the value: known bad domains, high NXDOMAIN rates per client, long or high-entropy subdomain labels with unusual record types (tunnelling), and first-seen or newly registered domains.
  • Caching hides repeats. Cloud resolvers and caching forwarders may log only the first query within a TTL, so build detections on unique names and client counts, not raw query volume.
  • Encrypted DNS changes where you can see. Clients and browsers that use DNS over HTTPS to external resolvers bypass enterprise logs entirely; route all DNS through enterprise resolvers and block the alternatives.

What DNS logs reveal

TechniqueATT&CK v20DNS signal
Command and control over DNST1071.004 Application Layer Protocol: DNSRegular queries (beaconing) to one domain, often TXT, NULL or CNAME records, with encoded subdomains
Domain generation algorithmsT1568.002 Dynamic Resolution: Domain Generation AlgorithmsMany lookups of random-looking names, mostly NXDOMAIN, from one client in a short period
Fast fluxT1568.001 Dynamic Resolution: Fast Flux DNSOne name returning many different IP addresses with very short TTLs
DNS tunnellingT1572 Protocol TunnelingLong labels, high character entropy, large numbers of unique subdomains under one parent domain, large TXT answers
Data exfiltration over DNST1048.003 Exfiltration Over Alternative Protocol: Exfiltration Over Unencrypted Non-C2 ProtocolHigh volume of unique query names to a single domain, carrying encoded data in the labels
Attacker-controlled or hijacked DNS infrastructureT1583.002 and T1584.002 DNS ServerYour own domains suddenly resolving to unfamiliar addresses or name servers

DNS logs also support investigations that are not about DNS: which hosts contacted a phishing domain, when a malware family first appeared, and which machines reached a cloud storage service during an exfiltration window.

Where to collect DNS logs

SourceWhat you getGapsBest use
Recursive resolver query logs (BIND, Unbound, Infoblox and similar)Client IP, query name, type, response code, often answer dataClient IP may be a forwarder or NAT address; no process namePrimary enterprise-wide source
Windows DNS Server Analytic logLookup, recursive, dynamic update and zone transfer eventsOff by default; volume at high query ratesActive Directory environments where domain controllers resolve for clients
Windows DNS Server Audit logChanges to server, zone and record settingsNot query dataDetecting malicious zone and record changes
Endpoint: Sysmon Event ID 22 DNSEventProcess that made the query, query name, results, cached or notEndpoint coverage only; Windows 8.1 or laterAttributing a query to a process
Endpoint detection and response agentsProcess-attributed DNS telemetryVendor-specific retention and fieldsSame as Sysmon, with better coverage
Network sensors (Zeek dns.log, passive DNS taps)Every query and response on a monitored segment, including to external resolversBlind to encrypted DNS; sensor placementCatching clients that bypass the enterprise resolver
Cloud resolvers (for example Route 53 Resolver query logs)Queries from VPCs, inbound and outbound endpoints, DNS Firewall actionsCached repeats not loggedCloud workload coverage
Protective DNS serviceBlocked and alerted queries matching threat intelligenceMay not give full query logsBlocking plus high-confidence alerts

Windows DNS Server

Microsoft documents two event logs under Applications and Services Logs, Microsoft, Windows, DNS-Server. The Audit log is enabled by default with no significant performance impact and records changes such as zone deletion (event 513), dynamic updates (519, 520) and configuration changes (541). The Analytic log records DNS traffic sent and received and is not enabled by default; its lookup events include 257 Response success, 258 Response failure and 259 Ignored query, with recursive events 260 Query out and 261 Response in, and zone transfer events from 265 to 276. Microsoft states that at 100,000 queries per second analytic logging can cause about 5 per cent performance degradation, with no apparent impact at 50,000 or fewer, and recommends monitoring performance when it is on. The separate Dns.log debug log is a troubleshooting tool, not a production log source.

Endpoint DNS events

Sysmon Event ID 22 is generated when a process executes a DNS query, whether successful or failed, cached or not. That last point matters: endpoint events see queries that a caching resolver would never log, and they carry the process image, so an analyst can tell a browser from a PowerShell process looking up the same domain.

Network sensors

Zeek's dns.log records, per query and response, the client and server addresses and ports, protocol, transaction ID, round trip time, query name, class and type (for example qtype_name "AAAA"), response code (rcode_name such as "NOERROR"), header flags (AA, TC, RD, RA), the answers array, their TTLs and whether the query was rejected. A sensor at the internet edge is the best way to find clients that ignore the enterprise resolver and send port 53 traffic directly outside.

Cloud resolvers

Amazon Route 53 Resolver query logging can record queries from specified VPCs, from on-premises resources through inbound endpoints, through outbound endpoints, and DNS Firewall rule matches, and deliver them to CloudWatch Logs, S3 or Firehose. AWS states that queries answered from the resolver cache within the TTL are not logged, so only the first query for a name in that period appears. Each entry includes the VPC, source IP, instance ID, query name, type, response code, response data and any firewall action. Other clouds have equivalent resolver logging; turn it on for every network, not only production.

Fields to keep and how to normalise them

  • Timestamp in UTC with millisecond precision.
  • Client identity: source IP plus, where available, host name, instance ID, user and process. Enrich IPs with DHCP and VPN lease logs so an address maps to a device at that time.
  • Query: full name, registered domain (the effective second-level domain computed with the Public Suffix List), record type and class.
  • Response: response code (NOERROR, NXDOMAIN, SERVFAIL, REFUSED), answers, TTLs, and response size.
  • Resolver and policy: which resolver answered and any block, redirect or sinkhole action.

Normalise every source to one schema in the SIEM so detections run once across Windows DNS, resolvers, sensors and cloud logs. Keep at least 90 days of searchable DNS logs and longer in cheaper storage: incident investigations regularly need to answer "who resolved this domain in the last six months?".

Detection logic that works

Known bad and newly seen domains

  • Threat intelligence match: compare the registered domain against curated indicator feeds. Alert on a match, but expect most value from blocking at the resolver instead.
  • First seen in your environment: keep a rolling list of every registered domain resolved in the last 30 to 90 days. A domain never seen before, queried by a server rather than a user device, is worth review.
  • Newly registered domains: enrich with registration age where you have a feed; very young domains are disproportionately malicious.

DGA

  • NXDOMAIN rate per client: alert when one client receives NXDOMAIN for more than a threshold of unique names (start with 50 in 10 minutes, then tune per segment).
  • Name randomness: score labels for character entropy, consonant runs and length; high scores across many queries from one client strengthen the alert.

Tunnelling and exfiltration

  • Unique subdomains per parent domain: alert when one parent domain receives hundreds of unique subdomains from one client in an hour.
  • Label length and total query length: names longer than about 50 characters in a single label, or approaching the 253 character limit, are rare in legitimate traffic.
  • Record type mix: a client making many TXT, NULL or CNAME queries to one domain is unusual for a workstation.
  • Bytes per domain: where response sizes are logged, total bytes per client per parent domain highlights data movement.

Beaconing

Look for regular intervals: the same client querying the same name at near-constant periods (for example every 60 seconds with low jitter) over hours, particularly from servers. Combine with low global popularity of the domain to reduce noise from software update checks.

Changes to your own DNS

Alert on Windows DNS Audit events for zone deletion and record changes outside change windows, and on changes in your public delegation (NS records) and key records. Attackers who control a zone can redirect mail and web traffic without touching an endpoint. See the Authoritative DNS and Registrar Account Security Guide.

Encrypted DNS and visibility

DNS over HTTPS (DoH, port 443) and DNS over TLS (DoT, port 853) protect queries from eavesdropping, but if a browser or application sends them to a public resolver, the enterprise resolver and its logs never see them. NIST SP 800-81 Rev. 3, the Secure Domain Name System Deployment Guide published in March 2026, lists encrypted DNS, protective DNS and DNS logging among its topics. Practical steps:

  1. Offer encrypted DNS on the enterprise resolver so clients get privacy without leaving your visibility.
  2. Configure clients and browsers by policy to use the enterprise resolver, and disable their built-in DoH to external providers through enterprise browser policy.
  3. Block outbound port 53 and 853 except from the enterprise resolvers, and block known public DoH endpoints at the web proxy or firewall.
  4. Detect bypass: alert on any internal host other than a resolver making DNS traffic to the internet, and on connections to known DoH resolver addresses.

Rolling it out

  1. Map resolution paths: list every resolver, forwarder, domain controller acting as DNS server, cloud resolver and protective DNS service, and which clients use each.
  2. Turn on logging at each tier, starting with the resolvers that serve the most clients. On Windows DNS, enable the Analytic log on a pilot server first, measure query rate and CPU, then expand.
  3. Add process attribution: deploy Sysmon Event ID 22 or the equivalent EDR telemetry to servers and high-value workstations.
  4. Ship and normalise into the SIEM with a common schema; enrich with DHCP, asset inventory and domain age.
  5. Deploy detections in alert-only mode for two weeks, tune thresholds per network segment, and document allowlisted domains (security tools and content delivery networks also generate long, random-looking names).
  6. Close bypass routes: egress rules for ports 53 and 853 and browser DoH policy.
  7. Roll back safely: if logging affects a busy resolver, reduce to sampled or response-failure logging on that server while capacity is added, rather than switching it off.

Small versus large organisations. A small organisation can get most of the benefit from a protective DNS service with query logging plus endpoint DNS telemetry from its EDR. Large organisations need resolver logs at every tier, network sensors at egress points and a data pipeline sized for billions of events a day; summarising to per-client, per-domain counts before long-term storage keeps costs manageable.

Where identity fits

Servers and workloads run as non-human identities, and their DNS behaviour is usually narrow and predictable: a payment service resolves a handful of partner APIs and nothing else. A workload suddenly resolving file sharing, paste or code hosting domains is a strong sign that its credentials or code are being misused. Use DNS logs to build a per-workload allowlist of expected domains and alert on anything outside it, and pair that with egress controls for the same identities. See the Cloud Workload Identity Guide.

Measuring coverage and effectiveness

  1. Percentage of client networks whose resolver logs reach the SIEM (target 100 per cent, including cloud networks).
  2. Percentage of servers with process-attributed DNS telemetry.
  3. Internal hosts making direct external DNS or DoT connections per week (target zero, other than resolvers).
  4. Median time from a malicious domain lookup to analyst triage.
  5. Detection true positive rate per rule, reviewed monthly.
  6. Searchable DNS log retention in days (target 90 or more).

Framework mapping

FrameworkReferenceHow DNS logging applies
NIST SP 800-53 Rev. 5AU-2 Event Logging, AU-12 Audit Record GenerationDNS query and change events defined as logged events
NIST SP 800-53 Rev. 5SI-4 System Monitoring, SC-7 Boundary ProtectionAnalysis of DNS for indicators; egress control of DNS paths
NIST CSF 2.0DE.CM-01, DE.AE-02Monitoring network services; analysing adverse events
NIST SP 800-81 Rev. 3Secure DNS deploymentDNS logging, protective DNS and encrypted DNS guidance
CIS Controls v8.1Safeguard 8.6 Collect DNS Query Audit Logs, Safeguard 9.2 Use DNS Filtering ServicesDirect requirements for query logs and filtering
MITRE ATT&CK v20T1071.004, T1568.002, T1568.001, T1572, T1048.003Techniques detectable in DNS logs

Common failure patterns

  • Logging the wrong tier: only the forwarder to the internet is logged, so every query appears to come from the domain controllers and no infected client can be identified.
  • Questions without answers: query names are logged but response codes and answers are not, which removes the NXDOMAIN and fast flux signals.
  • Analytic log never enabled: Windows DNS servers run with only the default Audit log, so there is no query data at all.
  • Counting raw volume in cloud logs: thresholds built on query counts miss tunnelling because cached repeats are not logged; count unique names instead.
  • DoH bypass ignored: browsers send DNS to public DoH resolvers and the SOC sees a fraction of real lookups.
  • Short retention: seven days of DNS logs cannot answer when a domain first appeared, which is often the first question in an incident.

Practitioner checklist

  • Map every resolver, forwarder and cloud resolver and the clients each serves.
  • Enable query logging with response codes and answers at the client-facing resolvers.
  • Enable the Windows DNS Analytic log on DNS servers after a performance pilot, and keep the Audit log monitored.
  • Collect Sysmon Event ID 22 or EDR DNS telemetry from servers and key workstations.
  • Turn on resolver query logging in every cloud network.
  • Normalise all sources to one schema with registered domain, client identity and response fields.
  • Deploy detections for intelligence matches, NXDOMAIN bursts, tunnelling patterns, beaconing and first-seen domains.
  • Block direct outbound DNS and DoT and disable external DoH in managed browsers.
  • Keep 90 days or more of searchable DNS logs.
  • Review rule precision monthly and track coverage metrics.

Standards and references

Related NHI Mgmt Group resources: DNS Security Guide · Authoritative DNS and Registrar Account Security Guide · Cloud Workload Identity Guide · File Integrity Monitoring Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 27 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.