DNSCrypt with Dnsmasq and dnscrypt-proxy2

  • This how-to describes the method for setting up DNSCrypt on OpenWrt.
  • It relies on Dnsmasq and dnscrypt-proxy2 that supports DNSCrypt v2, DNS over HTTPS and Anonymized DNSCrypt.
  • Follow DNS hijacking to intercept DNS traffic or use VPN to protect all traffic.
  • Encrypt your DNS traffic improving security and privacy.
    • Prevent DNS leaks and DNS hijacking.
  • Bypass regional restrictions using public DNS providers.
    • Escape DNS-based content filters and internet censorship.

Install the required packages. Enable DNS encryption.

# Install packages
opkg update
opkg install dnscrypt-proxy2
 
# Enable DNS encryption
service dnsmasq stop
uci set dhcp.@dnsmasq[0].noresolv="1"
uci set dhcp.@dnsmasq[0].localuse="1"
uci -q delete dhcp.@dnsmasq[0].server
uci add_list dhcp.@dnsmasq[0].server="127.0.0.53"
sed -i "32 s/.*/server_names = ['google', 'cloudflare']/" /etc/dnscrypt-proxy2/*.toml
uci commit dhcp
service dnsmasq start
service dnscrypt-proxy restart

LAN clients should use Dnsmasq as a primary resolver. Dnsmasq forwards DNS queries to dnscrypt-proxy2 which encrypts DNS traffic.

Note: These are the recommended options from the official DNSCrypt guide for OpenWrt on GitHub.

Note: Beware that the distributed configuration includes an activated block-names.txt. If you experience problems with some names, match them against this file first.

Verify domain name resolution with nslookup.

nslookup openwrt.org localhost

Check your DNS provider and test DNSSEC validation.

Collect and analyze the following information.

# Restart services
service log restart; service dnsmasq restart; service dnscrypt-proxy restart
 
# Log and status
logread -e dnsmasq; netstat -l -n -p | grep -e dnsmasq
logread -e dnscrypt-proxy; netstat -l -n -p | grep -e dnscrypt-proxy
 
# Runtime configuration
pgrep -f -a dnsmasq; pgrep -f -a dnscrypt-proxy
head -v -n -0 /etc/resolv.* /tmp/resolv.* /tmp/resolv.*/*
 
# Persistent configuration
uci show dhcp; grep -v -e "^\s*#" -e "^\s*$" /etc/dnscrypt-proxy2/dnscrypt-proxy.toml

dnscrypt-proxy2 is configured with Google DNS and Cloudflare DNS by default. You can change it to Google DNS or any other DoH or DNSCrypt provider. Use resolvers supporting DNSSEC validation if necessary. Specify several resolvers to improve fault tolerance.

# Configure DoH or DNSCrypt provider
# First, we need to set up a list of servers to use, example: (you have to change "exampledns" for the name of the DNS provider)
sed -i "32 s/.*/server_names = ['exampledns', 'exampledns2']/" /etc/dnscrypt-proxy2/*.toml
service dnscrypt-proxy restart
 
# Or you can also use only one server, example:
sed -i "32 s/.*/server_names = ['cloudflare']/" /etc/dnscrypt-proxy2/*.toml
service dnscrypt-proxy restart

ODoH (Oblivious DNS-over-HTTPS) prevents servers from learning anything about client IP addresses, by using intermediate relays dedicated to forwarding encrypted DNS data. Instead of directly sending a query to a target DoH server, the client encrypts it for that server, but sends it to a relay. An ODoH relay can only communicate with an ODoH server and an ODoH client. Relays can't get responses from a generic DoH server that doesn't support ODoH. You can change the ODoH servers and ODoH relays to any other.

# Enable ODoH on dnscrypt-proxy2
sed -i -e "s/.*odoh_servers.*/odoh_servers = true/; 689,700 s/#//" /etc/dnscrypt-proxy2/*.toml
 
# Configure "ODoH servers" and "ODoH relays"
odoh_servers="['odoh-cloudflare', 'odoh-crypto-sx']"
odoh_relays="['odohrelay-crypto-sx', 'odohrelay-koki-bcn']"
sed -i -e "32 s/.*/server_names = $odoh_servers/; 795 s/.*/routes = [/; 797 s/.*/    { server_name='*', via=$odoh_relays }/; 798 s/.*/]/" /etc/dnscrypt-proxy2/*.toml
service dnscrypt-proxy restart

More information about ODoH protocol: Improving DNS Privacy with Oblivious DoH in 1.1.1.1

Caveats: The Oblivious DNS-over-HTTPS protocol is still a work in progress. Servers and relays may not be very stable.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2023/10/14 05:29
  • by vgaetera