If you're setting up DNS for privacy or custom routing (like .onion domains), you might wonder whether dnsmasq or DNSCrypt is the right tool. While both handle DNS forwarding, DNSCrypt offers encryption and authentication, adding a layer of privacy that dnsmasq doesn't. Let’s take a look at how the two compare and whether you should use one or both in your setup.

What is DNSCrypt?

DNSCrypt is a protocol designed to secure DNS traffic between your device and a DNS resolver. It prevents your DNS queries from being seen or tampered with by encrypting the traffic. This makes it an excellent choice for anyone concerned about privacy or DNS spoofing.

How is dnsmasq Different?

dnsmasq, on the other hand, is a DNS forwarder and caching tool. It doesn't offer encryption, but it’s fantastic for setting up custom DNS routing and reducing latency by caching responses. For example, you can easily configure dnsmasq to forward .onion domains to a local Tor instance, which is something DNSCrypt isn’t designed for out of the box.

Comparing DNSCrypt and dnsmasq

Feature dnsmasq DNSCrypt
DNS Query Forwarding Yes (e.g., .onion to Tor DNS) Yes (with encrypted DNS queries)
DNS Caching Yes No (but you can use DNSCrypt with dnsmasq to add caching)
Encryption No (standard DNS queries in plaintext) Yes (DNS queries are encrypted)
Authentication No Yes (queries are authenticated to ensure they aren’t tampered with)
Anonymity No Yes (some DNSCrypt resolvers provide anonymity features)
Custom Resolvers Yes Yes (supports encrypted custom DNS resolvers)
Forwarding to Tor Yes (by setting up specific rules for .onion) Possible (but not the primary purpose; can be combined with other tools)
Advanced Features Basic DNS forwarding, caching Encryption, DNS over HTTPS (DoH), Anonymity, Authentication

Should You Use DNSCrypt, dnsmasq, or Both?

The answer depends on your needs. If you only want DNS encryption and privacy, DNSCrypt is a good standalone solution. However, if you need caching and custom DNS forwarding rules (like handling .onion domains for Tor), you’ll want to use dnsmasq as well.

Combining DNSCrypt and dnsmasq

You can get the best of both worlds by using DNSCrypt for encryption and dnsmasq for caching and custom routing. Here’s a setup that makes use of both:

  1. Install DNSCrypt and have it encrypt all DNS requests.
  2. Configure dnsmasq to forward .onion domain requests to Tor while forwarding regular DNS requests to the local DNSCrypt instance for encryption.

Here’s an example dnsmasq configuration for this setup:

# Forward .onion domains to the Tor DNS resolver
server=/onion/127.0.0.1#9053

# Forward all other DNS queries to the local DNSCrypt resolver (e.g., on port 5353)
server=127.0.0.1#5353

Why Use DNSCrypt?

If you're concerned about your DNS privacy, encryption is essential, and DNSCrypt provides that. While dnsmasq is great for custom routing, like forwarding .onion requests to Tor and caching responses, it doesn't encrypt anything on its own.

Conclusion

DNSCrypt and dnsmasq can work well together, offering both privacy through encryption and flexibility with caching and custom DNS routing. If you're serious about privacy and performance, combining them will give you the best of both worlds—protecting your DNS queries from prying eyes while also handling .onion domains or other custom DNS rules efficiently.

Additional Resources

I wrote this because I was working on something for Haveno, and figured I'd share the resources to, they are still a WIP. They are available on dockerhub under the HavenoDEX repo.