civil-and-structural-engineering
How to Use Dns to Block Malicious Domains and Protect Your Network
Table of Contents
In today's interconnected world, cybersecurity threats lurk behind every URL. Attackers constantly register new domains to host malware, launch phishing campaigns, and commandeer infected devices. One of the most efficient and proactive defenses you can deploy is DNS filtering — blocking malicious domains at the Domain Name System (DNS) layer. By intercepting DNS queries for known harmful sites before a connection is ever made, this technique stops threats before they can reach your network. Whether you manage a small home office or a large enterprise, understanding how to use DNS to block malicious domains is a foundational security practice that reduces risk with minimal overhead. This guide will walk you through the theory, the tools, and the step-by-step implementation to harden your network against domain-based attacks.
Understanding DNS and Its Role in Security
The Domain Name System is the internet's address book. When you type "example.com" into your browser, your device sends a DNS query to a resolver, which returns the corresponding IP address. Without DNS, we would have to memorize numeric addresses like 93.184.216.34. However, this fundamental protocol also presents a critical security chokepoint. Every DNS lookup is a request that can be intercepted, inspected, or redirected before the actual data transfer occurs.
DNS filtering works by maintaining a database of known malicious domains — sites hosting malware, phishing pages, command-and-control (C2) servers, or crypto-mining scripts. When a client requests resolution for one of these domains, the DNS resolver either refuses to resolve (returns a blocked page) or returns a safe IP address (often a sinkhole). This blocks the connection at the earliest possible point, before any application-layer data exchange. Because DNS is lightweight and universal (every device uses it), filtering at this layer provides blanket coverage across all devices on your network — including IoT gadgets, which are notoriously difficult to secure with traditional antivirus.
Why Block Malicious Domains?
Malicious domains are the delivery mechanism for most cyberattacks. According to industry reports, over 90% of malware campaigns use DNS to find their C2 servers. Phishing attacks rely on lookalike domains to trick users into entering credentials. Ransomware frequently phones home to a domain to receive encryption keys. By blocking these domains, you achieve several critical defenses:
- Prevent malware from reaching C2 servers — even if an endpoint is infected, it cannot communicate with its controller, effectively neutering the payload.
- Stop phishing visits — users cannot reach fraudulent login pages that mimic banks, cloud providers, or internal portals.
- Reduce data exfiltration risk — attackers using DNS tunneling or standard web traffic to exfiltrate data are thwarted.
- Improve network performance — by cutting off connection attempts to malicious hosts, you free up bandwidth and reduce noise in logs.
Methods of DNS Filtering
There are several ways to implement DNS-based blocking, ranging from zero-configuration public resolvers to fully custom on-premise servers. Your choice depends on network size, control needs, budget, and technical expertise.
Public DNS Filtering Services
Providers like OpenDNS (Cisco Umbrella), Cloudflare (1.1.1.2 / 1.1.1.3), and Quad9 (9.9.9.9) offer free or low-cost DNS resolvers that incorporate threat intelligence feeds. You simply point your router or device to these resolver IPs, and malicious domains are automatically blocked. This is the easiest approach for home users and small offices.
Self-Hosted DNS Filtering (Pi-hole, BIND, Unbound)
For those who want control over blocklists, logs, and fine-grained policies, running your own DNS filter on a Raspberry Pi or a small server is ideal. Pi-hole is the most popular community-driven solution, combining a DNS sinkhole with a web dashboard. BIND with Response Policy Zones (RPZ) is a more enterprise-focused option that integrates with existing infrastructure. These setups allow you to subscribe to curated blocklists, create custom allow/block rules, and monitor DNS traffic in real time.
Hardware or Cloud-Based DNS Firewalls
Enterprise-grade solutions such as Cisco Umbrella, Palo Alto Networks DNS Security, or Infoblox DNS Firewall provide advanced threat intelligence, machine learning, and integration with SIEM tools. These are often subscription-based and suited for large organizations with dedicated security teams.
Setting Up DNS Filtering with Public DNS
Let’s walk through the most straightforward method: configuring your router or device to use a filtered public DNS resolver. No additional hardware or software is required.
Step 1: Choose a Filtered Provider
- OpenDNS (Cisco Umbrella): 208.67.222.222 and 208.67.220.220 — blocks phishing, malware, and botnets. Offers family shield (208.67.222.123) for content filtering.
- Cloudflare 1.1.1.2 (malware blocking) and 1.1.1.3 (malware + adult content).
- Quad9: 9.9.9.9 and 149.112.112.112 — uses threat intelligence from multiple sources, no logging.
- AdGuard DNS: 94.140.14.14 (default) and 94.140.14.15 (family protection) — blocks ads, trackers, and malware.
Step 2: Update Router DHCP Settings
Log into your router’s admin interface. Navigate to the DHCP or WAN settings. Replace the default DNS fields with the chosen provider’s IPs. Save and reboot the router. All devices that obtain IP addresses via DHCP will now use the filtered resolver. Some routers also allow you to force DNS for all clients regardless of device settings.
Step 3: Test the Configuration
Visit a known test domain provided by your DNS service — for example, internetbadguys.com (OpenDNS) or use 1.1.1.1/help (Cloudflare) to verify the resolver. Attempt to navigate to a known malicious domain (use caution) or use a test URL like phishingtest.com if available. The page should be blocked with a redirect to a warning page.
Building Your Own DNS Filter with Pi-hole
Pi-hole is a lightweight, open-source DNS sinkhole that runs on a Raspberry Pi, Docker, or any Linux machine. It acts as a DNS server that discards or redirects queries for domains on its blocklist. With a web dashboard, you can see exactly which devices are making DNS requests, query trends, and real-time blocking statistics.
Hardware and Installation
A Raspberry Pi 3 or 4 (or any Debian-based VM) works perfectly. Install Pi-hole using a single command from the official Pi-hole website:
curl -sSL https://install.pi-hole.net | bash
During installation, choose your upstream DNS (e.g., Cloudflare, Quad9) and a blocklist. You can select from pre-defined lists or add custom URLs later. Set a static IP for the Pi-hole so all network devices can reach it.
Configuring Clients to Use Pi-hole
On your router, set the DHCP DNS to the Pi-hole’s IP address. Alternatively, configure each device manually (not recommended for more than a few devices). Once set, all DNS queries will pass through Pi-hole.
Adding Blocklists
Pi-hole comes with a default blocklist (StevenBlack). To expand coverage, add lists from trusted sources such as:
- Firebog (curated blocklists for ads, malware, tracking)
- ransomwaretracker.abuse.ch — dedicated ransomware domains
- ispyair.com — malicious domains from various feeds
Be careful not to over-block — some legitimate services (like some CDNs) may be affected. Use the whitelist function to unblock false positives.
Monitoring and Maintenance
Pi-hole’s dashboard provides real-time query logs, top domains, top clients, and blocked percentages. Regularly review logs for unusual patterns — repeated queries to blocked domains may indicate an infected device. Update blocklists weekly (Pi-hole does this automatically if configured).
Advanced DNS Filtering with BIND and RPZ
For organizations that already run BIND as their authoritative or caching DNS server, Response Policy Zones (RPZ) offer a robust method to block malicious domains without changing the DNS software. RPZ allows you to override standard DNS responses based on a zone file containing malicious domains.
Setting Up RPZ
- Download threat feeds in RPZ format (e.g., from Spamhaus, Emerging Threats, or commercial vendors).
- Convert the feeds into a BIND-compatible zone file with the appropriate RPZ options (e.g.,
warnto log,blockto sinkhole). - Configure BIND to include the RPZ file in
named.conf:
response-policy {
zone "rpz.blocklist" {
policy given;
};
};
This approach allows per-client blocking policies, logging, and integration with existing DNS infrastructure. However, it requires deeper knowledge of BIND configuration and ongoing management of RPZ file updates.
Best Practices for DNS Security
DNS filtering is powerful, but it is not a silver bullet. Implement these best practices to maximize effectiveness:
- Layer filtering with other security tools — combine DNS blocking with firewalls, web proxies, endpoint detection, and email security for defense-in-depth.
- Enable DNSSEC — validates DNS responses to prevent cache poisoning. Most filtered resolvers support DNSSEC validation.
- Use local logs and alerting — monitor for repeated blocked queries, which may indicate a compromised device. Set up alerts for high block rates.
- Regularly update blocklists — threat actors constantly register new domains. Automated updates (hourly or daily) are critical.
- Whitelist carefully — test domains before adding them to the allow list. Use a temporary exception policy if possible.
- Block at the router, not just endpoints — ensure IoT, guest networks, and guest devices are also filtered.
- Consider DoH and DoT — some clients attempt to bypass DNS filters using encrypted DNS (DNS over HTTPS/TLS). Block outbound DNS on port 53 to unapproved resolvers, or redirect DoH traffic to your filter.
Conclusion
Using DNS to block malicious domains is a highly effective, low-friction security measure that should be part of every organization’s defense strategy. Whether you opt for a public filtered resolver like OpenDNS or Quad9, build a Pi-hole sinkhole, or deploy an enterprise DNS firewall with RPZ, the core principle is the same: intercept DNS queries for known bad destinations and halt attacks before they can establish a foothold. The implementation does not require expensive hardware or deep expertise — start small, test, and gradually expand your blocklist. In a threat landscape where domain-based attacks remain the primary vector, DNS filtering gives you a powerful vantage point to protect your network proactively. Take action today to close this gap and reduce your exposure to malware, phishing, and ransomware campaigns.