← Back to all modules
πŸ”
βš™οΈ Security Engineers Β· Module 4

DNS-Level Security

Deploy Pi-hole or NextDNS for network-wide ad/tracker blocking, configure DNS-over-HTTPS/TLS, create per-device profiles, and monitor DNS queries for threats.

🌐

DNS as a Security Layer

Every network request begins with DNS. Before your browser connects to evil-phishing-site.com, it asks a DNS resolver for the IP address. This makes DNS a natural chokepoint for security enforcement β€” if you control DNS resolution, you can block threats before a single byte of malicious content reaches your network.

The DNS Security Stack

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Application Layer              β”‚
β”‚    (Browser, apps, IoT devices)          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚           DNS Resolver                    β”‚
β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
β”‚    β”‚ 1. Blocklist filtering      β”‚       β”‚
β”‚    β”‚ 2. Threat intelligence      β”‚       β”‚
β”‚    β”‚ 3. Query logging/monitoring β”‚       β”‚
β”‚    β”‚ 4. Encrypted transport      β”‚       β”‚
β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Upstream DNS (DoH/DoT)           β”‚
β”‚    Cloudflare, Quad9, NextDNS            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Authoritative DNS                β”‚
β”‚    Root β†’ TLD β†’ Domain nameservers       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

What DNS-Level Security Catches

1. Ad Networks & Trackers

Blocking at DNS level prevents the connection entirely β€” no request is made, so no tracking pixel is loaded, no fingerprinting script runs, and no ad network sees your IP.

# Example: Blocking Facebook tracking across the internet
# These domains appear on sites that use Facebook pixel
0.0.0.0 connect.facebook.net
0.0.0.0 pixel.facebook.com
0.0.0.0 graph.facebook.com

2. Malware Command & Control

Malware often uses DNS for C2 communication. Blocking known C2 domains at the resolver level prevents compromised devices from phoning home:

# Common malware C2 patterns:
# - Recently registered domains (DGA - Domain Generation Algorithms)
# - Dynamic DNS providers (duckdns.org, no-ip.com)
# - Unusually long subdomains (data exfiltration via DNS)

3. Phishing Domains

Threat intelligence feeds maintain lists of known phishing domains. DNS blocking stops users from reaching these even if they click a phishing link.

4. Data Exfiltration via DNS

Sophisticated attackers encode stolen data in DNS queries:

# DNS exfiltration example:
# Stolen data: credit_card=4111111111111111
# Encoded as: Y3JlZGl0X2NhcmQ9NDExMTExMTExMTExMTExMQ==.evil.com
# Each subdomain query sends a chunk of stolen data
# The authoritative nameserver for evil.com collects the fragments

# Detection: unusually long subdomain labels, high entropy in labels,
# high volume of unique subdomain queries to a single domain

DNS Protocol Vulnerabilities

Traditional DNS (port 53, UDP) is transmitted in plaintext:

# Anyone on your network can see your DNS queries:
tcpdump -i en0 port 53 -nn
# Output: 192.168.1.100 > 8.8.8.8: A? banking-site.com
# Your ISP, coffee shop WiFi operator, or network attacker
# can see every domain you visit

This is why encrypted DNS (DoH/DoT) matters:

Protocol Port Encryption Visibility
DNS (traditional) 53/UDP None ISP sees all queries
DNS-over-TLS (DoT) 853/TCP TLS 1.3 ISP sees you're using DoT, not queries
DNS-over-HTTPS (DoH) 443/TCP TLS 1.3 Indistinguishable from HTTPS traffic
DNSCrypt 443/UDP X25519 + XSalsa20 Less common but strong

Why You Need Your Own DNS Infrastructure

Using your ISP's default DNS means:

  1. Your ISP logs every domain you visit
  2. No ad/tracker blocking
  3. No protection against malware domains
  4. Possible DNS hijacking for ad injection
  5. No encryption of queries

Even using 8.8.8.8 (Google) or 1.1.1.1 (Cloudflare) directly is better, but you still lack filtering and local network-level control. Running your own DNS resolver gives you all of this.

1 / 5

πŸ›‘οΈ CyberSafe β€” Online safety training for the whole family.