DNSCrypt with Dnsmasq and dnscrypt-proxy

  • Encrypt your DNS traffic improving security and privacy.
    • Prevent DNS leak and DNS hijacking.
  • Bypass regional restrictions using public DNS providers.
    • Escape DNS-based content filters and internet censorship.

Install the packages and configure DNS encryption.

# Install packages
opkg update
opkg install dnsmasq dnscrypt-proxy
# Configure DNSCrypt provider
uci set dnscrypt-proxy.@dnscrypt-proxy[0].resolver="cisco"
uci set dnscrypt-proxy.@dnscrypt-proxy[0].address=""
uci set dnscrypt-proxy.@dnscrypt-proxy[0].port="5253"
uci commit dnscrypt-proxy
/etc/init.d/dnscrypt-proxy restart
# Enable DNS encryption
uci -q delete dhcp.@dnsmasq[0].server
DNSCRYPT_ADDR="$(uci get dnscrypt-proxy.@dnscrypt-proxy[0].address)"
DNSCRYPT_PORT="$(uci get dnscrypt-proxy.@dnscrypt-proxy[0].port)"
uci add_list dhcp.@dnsmasq[0].server="${DNSCRYPT_SERV}"
# Enforce DNS encryption for LAN clients
/etc/init.d/dnsmasq stop
uci set dhcp.@dnsmasq[0].noresolv="1"
uci commit dhcp
/etc/init.d/dnsmasq start

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

Verify that domain name resolution works.

nslookup openwrt.org localhost

Check your DNS provider. Make sure there is no DNS leak.

Test DNSSEC validation.

Collect and analyze the following information.

# Restart services
/etc/init.d/log restart; /etc/init.d/dnsmasq restart; /etc/init.d/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; uci show dnscrypt-proxy

Install the necessary packages if you want to manage the settings using web interface.

# Install packages
opkg update
opkg install luci-app-dnscrypt-proxy
/etc/init.d/rpcd restart
  • Navigate to LuCI → Network → DHCP and DNS to configure Dnsmasq.
  • Navigate to LuCI → Services → DNSCrypt-Proxy to configure dnscrypt-proxy.

dnscrypt-proxy is configured with Cisco DNS. You can change it to DNSCrypt.eu or any other DNSCrypt provider. Make sure the resolvers support DNSSEC validation if required. Specify several resolvers to improve fault tolerance.

# Update DNSCrypt provider database
sed -i -e "/^dnscrypt\.eu-nl,/a $(sed -n -e "
s/DNSCrypt\.eu Holland/\0 over IPv6/
" /usr/share/dnscrypt-proxy/dnscrypt-resolvers.csv)" \
# Configure DNSCrypt provider
while uci -q delete dnscrypt-proxy.@dnscrypt-proxy[0]; do :; done
uci set dnscrypt-proxy.dns6a="dnscrypt-proxy"
uci set dnscrypt-proxy.dns6a.resolver="dnscrypt.eu-dk-ipv6"
uci set dnscrypt-proxy.dns6a.address="[::1]"
uci set dnscrypt-proxy.dns6a.port="5253"
uci set dnscrypt-proxy.dns6b="dnscrypt-proxy"
uci set dnscrypt-proxy.dns6b.resolver="dnscrypt.eu-nl-ipv6"
uci set dnscrypt-proxy.dns6b.address="[::1]"
uci set dnscrypt-proxy.dns6b.port="5254"
uci set dnscrypt-proxy.dnsa="dnscrypt-proxy"
uci set dnscrypt-proxy.dnsa.resolver="dnscrypt.eu-dk"
uci set dnscrypt-proxy.dnsa.address=""
uci set dnscrypt-proxy.dnsa.port="5255"
uci set dnscrypt-proxy.dnsb="dnscrypt-proxy"
uci set dnscrypt-proxy.dnsb.resolver="dnscrypt.eu-nl"
uci set dnscrypt-proxy.dnsb.address=""
uci set dnscrypt-proxy.dnsb.port="5256"
uci commit dnscrypt-proxy
/etc/init.d/dnscrypt-proxy restart
uci -q delete dhcp.@dnsmasq[0].server
DNSCRYPT_ADDR="$(uci -q get dnscrypt-proxy.@dnscrypt-proxy[0].address)"
DNSCRYPT_PORT="$(uci -q get dnscrypt-proxy.@dnscrypt-proxy[0].port)"
uci -q delete dnscrypt-proxy.@dnscrypt-proxy[0]
do uci add_list dhcp.@dnsmasq[0].server="${DNSCRYPT_SERV}"
uci revert dnscrypt-proxy
uci commit dhcp
/etc/init.d/dnsmasq restart
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: 2021/03/21 07:50
  • by vgaetera