This is a new thread addressing getting DNSCrypt-Proxy 2, dnsmasq and DNSSEC running on the Edgerouter Lite (the same technique should work on most of the other router models). Although this is a continuation of “dnscrypt-proxy, DNSSEC and dnsmasq on Edgerouter Lite,” there are some significant differences between DNSCrypt-Proxy 2 and its predecessor that merit a clean slate for discussion.
To get started, first and foremost, the DNSCrypt-Proxy 2 binary is needed, get the MIPS64 binary from the releases directory. The binary comes with some sample configuration files. At a minimum, example-dnscrypt-proxy.toml needs to be renamed to dnscrypt-proxy.toml. By default, the binary expects the configuration files to be in the same directory; however, that can be changed on the command-line. I chose to put the binary in /config/sbin and the configuration files in /config/etc/dnscrypt-proxy directories.
A few support scripts are required:
/config/scripts/post-config.d/dnscrypt.sh
This sets up a persistent directory in the /config filesystem for dnsmasq to save the timestamp created by the dnssec-timestamp option, and then starts the dnscrypt-proxy process:
#!/bin/sh
# Check that persistent (/config filesystem) var directory exists, if not, create it and set ownership
if [ ! -d /config/var/run/dnsmasq ]; then
/bin/mkdir -p /config/var/run/dnsmasq; /bin/chown dnsmasq /config/var/run/dnsmasq;
fi;
/config/sbin/dnscrypt-proxy \
-config /config/etc/dnscrypt-proxy/dnscrypt-proxy.toml &
exit 0
/config/scripts/post-config.d/dnt-hup.sh
This uses ntp's ntp-wait Perl script to HUP dnsmasq when ntp is in a synchronized state (which is useful if the dnssec-no-timecheck option is used for dnsmasq). The ntp-wait command can take quite a while to complete - I clocked it at about 19 minutes on a sample boot - which is why it's forced into the background, otherwise the boot process would block here.
#!/bin/sh
(
# -b # Force the time to be stepped using the settimeofday() system call, rather # than slewed (default) using the adjtime() system call. This option should # be used when called from a startup file at boot time. # -u # Use an unprivileged port to send the packets from. This option is useful # when you are behind a firewall that blocks incoming traffic to privileged # ports, and you want to synchronize with hosts beyond the firewall. The -d # option always uses unprivileged ports. # -s # Log actions by way of the syslog(3C) facility rather than to the standard # output -- a useful option when running the program from cron(1M). /usr/bin/logger -p user.notice Waiting for ntpdate to synchronize time from 0.ubnt.pool.ntp.org... /usr/sbin/ntpdate -bus `/usr/bin/host 0.ubnt.pool.ntp.org 8.8.8.8 | /usr/bin/awk '/has address/ { print $4 ; exit }'`
) &
(
# dnssec-no-timecheck # DNSSEC signatures are only valid for specified time windows, and should # be rejected outside those windows. This generates an interesting # chicken-and-egg problem for machines which don't have a hardware real # time clock. For these machines to determine the correct time typically # requires use of NTP and therefore DNS, but validating DNS requires that # the correct time is already known. Setting this flag removes the # time-window checks (but not other DNSSEC validation.) only until the # dnsmasq process receives SIGHUP. The intention is that dnsmasq should # be started with this flag when the platform determines that reliable # time is not currently available. As soon as reliable time is # established, a SIGHUP should be sent to dnsmasq, which enables time # checking, and purges the cache of DNS records which have not been # throughly checked. # The ntp-wait program blocks until ntpd is in synchronized state. This # can be useful at boot time, to delay the boot sequence until after # "ntpd -g" has set the time. /usr/bin/logger -p user.notice Waiting for ntpd to synchronize... /usr/sbin/ntp-wait -n 1000 -s 6 if [ $? -eq 0 ] then /usr/bin/logger -p user.notice Sending SIGHUP to dnsmasq... /usr/bin/pkill -SIGHUP -e -F /var/run/dnsmasq/dnsmasq.pid 2>&1 | logger -p user.notice exit 0 else /usr/bin/logger -p user.notice Could not synchronize time. Giving up. DNSSEC signatures are not timechecked. exit 1 fi
) &
Lastly, the router configuration, including the dnsmasq configuration (note the delete command that's discussed in this thread to make sure there isn't a server=127.0.0.1 line in /etc/dnsmasq.conf that overrides pointing to the dnscrypt-proxy server we have running on an unprivledged port):
delete service dns forwarding system
set service dns forwarding cache-size 1024
set service dns forwarding listen-on switch0
set service dns forwarding listen-on eth0
set service dns forwarding options domain-needed
set service dns forwarding options bogus-priv
set service dns forwarding options except-interface=eth1
set service dns forwarding options stop-dns-rebind
set service dns forwarding options 'server=127.0.0.1#5353'
set service dns forwarding options trust-anchor=.,19036,8,2,49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5
set service dns forwarding options trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D
set service dns forwarding options dnssec
set service dns forwarding options dnssec-check-unsigned
Choose one of the following (dnssec-timestamp or dnssec-no-timecheck):
set service dns forwarding options dnssec-timestamp=/config/var/run/dnsmasq/dnsmasq.time
OR
set service dns forwarding options dnssec-no-timecheck