pkg install dnscrypt-proxypkg install nano
mv /usr/local/etc/rc.d/dnscrypt-proxy /usr/local/etc/rc.d/dnscrypt-proxy.originalnano /usr/local/etc/rc.d/dnscrypt-proxy
#!/bin/sh## $FreeBSD: head/dns/dnscrypt-proxy/files/dnscrypt-proxy.in 373758 2014-12-02 09:21:49Z xmj $## PROVIDE: dnscrypt_proxy# REQUIRE: SERVERS cleanvar# BEFORE: named local_unbound unbound# KEYWORD: shutdown## Add the following lines to /etc/rc.conf to enable dnscrypt-proxy:## dnscrypt_proxy_instances (str): Set to "dnscrypt_proxy" by default.# List of dnscrypt_proxy instance id's,# e.g. "dnscrypt_proxy_1 dnscrypt_proxy_2", etc.# {instance_id}_enable (bool): Set to NO by default.# Set to YES to enable dnscrypt-proxy.# {instance_id}_uid (str): Set to "_dnscrypt-proxy" by default.# User to switch to after starting.# {instance_id}_resolver (str): Set to "opendns" by default.# Choose a different upstream resolver.# {instance_id}_pidfile (str): default: "/var/run/dnscrypt-proxy.pid"# Location of pid file.# {instance_id}_logfile (str): default: "/var/log/dnscrypt-proxy.log"# Location of log file.## To redirect a local resolver through dnscrypt-proxy, point it at 127.0.0.2# and add the following to rc.conf:# ifconfig_lo0_alias0="inet 127.0.0.2 netmask 0xffffffff"# dnscrypt_proxy_flags='-a 127.0.0.2'. /etc/rc.subrname=dnscrypt_proxyload_rc_config ${name}: ${dnscrypt_proxy_instances="${name}"}: ${dnscrypt_proxy_enable:=NO}dnscrypt_proxy_enable_tmp=${dnscrypt_proxy_enable}command=/usr/local/sbin/dnscrypt-proxyprocname=/usr/local/sbin/dnscrypt-proxyfor i in $dnscrypt_proxy_instances; do name=${i} eval ${name}_enable=${dnscrypt_proxy_enable_tmp} rcvar=${name}_enable load_rc_config ${i} eval dnscrypt_proxy_uid_tmp=\${${i}_uid} eval dnscrypt_proxy_resolver_tmp=\${${i}_resolver} eval dnscrypt_proxy_pidfile_tmp=\${${i}_pidfile} eval dnscrypt_proxy_logfile_tmp=\${${i}_logfile}: ${dnscrypt_proxy_uid_tmp:=_dnscrypt-proxy} # User to run daemon as: ${dnscrypt_proxy_resolver_tmp:=opendns} # resolver to use: ${dnscrypt_proxy_pidfile_tmp:=/var/run/${i}.pid} # Path to pid file: ${dnscrypt_proxy_logfile_tmp:=/var/log/${i}.log} # Path to log file command_args="-d -p ${dnscrypt_proxy_pidfile_tmp} -l ${dnscrypt_proxy_logfile_tmp} -u ${dnscrypt_proxy_uid_tmp} -R ${dnscrypt_proxy_resolver_tmp}" pidfile=${dnscrypt_proxy_pidfile_tmp} _rc_restart_done=false # workaround for: service dnscrypt-proxy restart run_rc_command "$1"done
chmod a+x /usr/local/etc/rc.d/dnscrypt-proxy
nano /etc/rc.conf
## Use other method instead of lo0 alias #### ifconfig lo0 alias 127.0.0.2/32 #### ifconfig lo0 alias 127.0.0.3/32 #### ifconfig lo0 alias 127.0.0.4/32 ##dnscrypt_proxy_enable="YES"dnscrypt_proxy_instances="dnscrypt_proxy_1 dnscrypt_proxy_2 dnscrypt_proxy_3"dnscrypt_proxy_1_resolver="ipredator"dnscrypt_proxy_1_flags="-a 127.0.0.2:53 -l /var/log/"dnscrypt_proxy_2_resolver="dnscrypt.eu-dk"dnscrypt_proxy_2_flags="-a 127.0.0.3:53 -l /var/log/"dnscrypt_proxy_3_resolver="d0wn-lu-ns1"dnscrypt_proxy_3_flags="-a 127.0.0.4:53 -l /var/log/"
pkg install wgetwget -O /usr/local/share/dnscrypt-proxy/dnscrypt-resolvers.csv https://raw.githubusercontent.com/jedisct1/dnscrypt-proxy/master/dnscrypt-resolvers.csv
Next go to System-->Setting--->General---> Specify the dns servers at 127.0.0.1 127.0.0.2 and 127.0.0.3
In OpnSense GUI, go to Services-->DNS ForwarderEnable it, set it to port 53. I also specified the interface and set it to strict.
#!/usr/local/bin/bashproxy_tmp=/tmp/tmp_dnscrypt_proxyproxy_csv=/usr/local/share/dnscrypt-proxy/dnscrypt-resolvers.csvcheck_dnscrypt=$(pkg info -ak | grep 'dnscrypt-proxy-' | grep 'yes' | wc -l | tr -d ' ')conf_backup=/root/dnscrypt_proxy_backupconf_dnscrypt=/usr/local/etc/rc.d/dnscrypt-proxyversions_check=$(pkg version -vx dnscrypt-proxy | grep 'up-to-date with remote' | wc -l | tr -d ' ')update_lock() { pkg unlock -qy dnscrypt-proxy pkg install dnscrypt-proxy pkg lock -qy dnscrypt-proxy}update_unlock() { pkg install dnscrypt-proxy pkg lock -qy dnscrypt-proxy}check_proxy_csv() { if [ -f $proxy_tmp ]; then rm -rf $proxy_tmp fi mkdir $proxy_tmp wget --no-cache -O $proxy_tmp/dnscrypt-resolvers-new.csv https://raw.githubusercontent.com/jedisct1/dnscrypt-proxy/master/dnscrypt-resolvers.csv if ! cmp $proxy_tmp/dnscrypt-resolvers-new.csv $proxy_csv >/dev/null 2>&1; then mv $proxy_tmp/dnscrypt-resolvers-new.csv $proxy_csv fi rm -rf $proxy_tmp}check_conf() { checkprocess=$(ps -U_dnscrypt-proxy | grep 'dnscrypt_proxy_' | wc -l | tr -d ' ') diff -q $conf_backup $conf_dnscrypt 1>/dev/null case "$?" in 0) # Alles jut check_proxy_csv if [ "$checkprocess" -eq 0 ]; then service dnscrypt-proxy start else service dnscrypt-proxy restart sleep 3 fi ;; 1) if [ "$checkprocess" -gt 0 ]; then service dnscrypt-proxy stop sleep 3 fi cp "$conf_backup" "$conf_dnscrypt" check_proxy_csv service dnscrypt-proxy start ;; esac}case "$check_dnscrypt" in 1) if [ "$versions_check" -eq 0 ]; then update_lock fi check_conf ;; 0) if [ "$versions_check" -eq 0 ]; then update_unlock else pkg lock -qy dnscrypt-proxy fi check_conf ;;esac
#!/bin/sh## $FreeBSD$# # PROVIDE: dnscrypt_proxy# REQUIRE: SERVERS cleanvar ldconfig# BEFORE: named local_unbound unbound# KEYWORD: shutdown## This script supports running multiple instances of dnscrypt-proxy.# To run additional instances link this script to something like# % ln -s dnscrypt-proxy dnscrypt-proxy_foo# and define additional dnscrypt_proxy_foo_* variables in one of# /etc/rc.conf, /etc/rc.conf.local or /etc/rc.conf.d/dnscrypt-proxy_foo## The name of the addition instance should contain only letters (a to z or A to Z),# numbers (0 to 9) or the underscore character (_).## Below NAME should be substituted with the name of this script. By default# it is dnscrypt_proxy, so read as dnscrypt_proxy_enable. If you linked the script to# dnscrypt-proxy_foo, then read as dnscrypt_proxy_foo_enable etc.## The following variables are supported (defaults are shown).# You can place them in any of# /etc/rc.conf, /etc/rc.conf.local or /etc/rc.conf.d/NAME## NAME_enable="NO" # set to YES to enable dnscrypt-proxy instance## # optional:# NAME_flags= # additional command line arguments# NAME_configfile="/usr/local/etc/dnscrypt-proxy/NAME.conf" # Will override all other# settings and only use the config file.# NAME_uid (str): Set to "_dnscrypt-proxy" by default.# User to switch to after starting.# NAME_resolver (str):Set to "cisco" by default.# Choose a different upstream resolver.# NAME_pidfile (str): default: "/var/run/NAME.pid"# Location of pid file.# NAME_logfile (str): default: "/var/log/NAME.log"# Location of log file.## To redirect a local resolver through dnscrypt-proxy, point it at 127.0.0.x# and add the following to rc.conf:# ifconfig_lo0_alias0="inet 127.0.0.x netmask 0xffffffff"# NAME_flags='-a 127.0.0.x'. /etc/rc.subr# service(8) does not create an authentic environment, try to guess,# and as of 10.3-RELEASE-p0, it will not find the indented name=# assignments below. So give it a default.# Trailing semicolon also for service(8)'s benefit:name="$file" ;case "$0" in/etc/rc*) # during boot (shutdown) $0 is /etc/rc (/etc/rc.shutdown), # so get the name of the script from $_file name="$_file" ;;*/service) # do not use this as $0 ;;*) name="$0" ;;esac# default name to "dnscrypt_proxy" if guessing failed# Trailing semicolon also for service(8)'s benefit:name="dnscrypt_proxy${name##*dnscrypt-proxy}" ;rcvar=${name}_enablestop_postcmd(){ rm -f "$pidfile" || warn "Could not remove $pidfile."}# command and argumentscommand="/usr/local/sbin/dnscrypt-proxy"# run this laststop_postcmd="stop_postcmd"load_rc_config ${name}eval ": \${${name}_enable:=\"NO\"}"eval ": \${${name}_configfile:=\"/usr/local/etc/dnscrypt-proxy/${name}.conf\"}"eval ": \${${name}_uid:=\"_dnscrypt-proxy\"}" # User to run daemon aseval ": \${${name}_resolver:=\"cisco\"}" # resolver to useeval ": \${${name}_pidfile:=\"/var/run/${name}.pid\"}" # Path to pid fileeval ": \${${name}_logfile:=\"/var/log/${name}.log\"}" # Path to log fileconfigfile="$(eval echo \${${name}_configfile})"uid="$(eval echo \${${name}_uid})"resolver="$(eval echo \${${name}_resolver})"pidfile="$(eval echo \${${name}_pidfile})"logfile="$(eval echo \${${name}_logfile})"if [ -f "$configfile" ]; thencommand_args="$configfile"elsecommand_args="-d -p $pidfile -l $logfile -u $uid -R $resolver"firun_rc_command "$1"
With a fresh 17.7 install /etc/rc.conf will be ignored at bootup, so it will not start automatically, I have to service dnscrypt-proxy start.What kind of sorcery do you use for this to work?
I am not sure but it looks like dnscrypt-proxy (enabled in /etc/rc.conf) doesn´t start when Unbound is already running. In the dnscrypt-proxy we see the directive "BEFORE: unbound..." but this controls the normal "service... start" process. How can I make sure that the Unbound-Plugin will be started AFTER "service dnscrypt-proxy start" at boot time?
QuoteI am not sure but it looks like dnscrypt-proxy (enabled in /etc/rc.conf) doesn´t start when Unbound is already running. In the dnscrypt-proxy we see the directive "BEFORE: unbound..." but this controls the normal "service... start" process. How can I make sure that the Unbound-Plugin will be started AFTER "service dnscrypt-proxy start" at boot time?Unbound is part of our system, a base plugin if you will. We start auxiliary services afterwards, so in order to fix this we need to make dnscrypt-proxy a plugin as well to adhere to a correct starting order.
#!/bin/sh## $FreeBSD: head/dns/dnscrypt-proxy/files/dnscrypt-proxy.in 373758 2014-12-02 09:21:49Z xmj $## PROVIDE: dnscrypt_proxy# REQUIRE: ldconfig cleanvar# BEFORE: SERVERS# KEYWORD: shutdown## Add the following lines to /etc/rc.conf to enable dnscrypt-proxy:## dnscrypt_proxy_instances (str): Set to "dnscrypt_proxy" by default.# List of dnscrypt_proxy instance id's,# e.g. "dnscrypt_proxy_1 dnscrypt_proxy_2", etc.# {instance_id}_enable (bool): Set to NO by default.# Set to YES to enable dnscrypt-proxy.# {instance_id}_uid (str): Set to "_dnscrypt-proxy" by default.# User to switch to after starting.# {instance_id}_resolver (str): Set to "opendns" by default.# Choose a different upstream resolver.# {instance_id}_pidfile (str): default: "/var/run/dnscrypt-proxy.pid"# Location of pid file.# {instance_id}_logfile (str): default: "/var/log/dnscrypt-proxy.log"# Location of log file.## To redirect a local resolver through dnscrypt-proxy, point it at 127.0.0.2# and add the following to rc.conf:# ifconfig_lo0_alias0="inet 127.0.0.2 netmask 0xffffffff"# dnscrypt_proxy_flags='-a 127.0.0.2'. /etc/rc.subrname=dnscrypt_proxyrcvar=dnscrypt_proxy_enableload_rc_config ${name}: ${dnscrypt_proxy_instances="${name}"}: ${dnscrypt_proxy_enable:=NO}dnscrypt_proxy_enable_tmp=${dnscrypt_proxy_enable}command=/usr/local/sbin/dnscrypt-proxyprocname=/usr/local/sbin/dnscrypt-proxyfor i in $dnscrypt_proxy_instances; do name=${i} eval ${name}_enable=${dnscrypt_proxy_enable_tmp} rcvar=${name}_enable load_rc_config ${i} eval dnscrypt_proxy_uid_tmp=\${${i}_uid} eval dnscrypt_proxy_resolver_tmp=\${${i}_resolver} eval dnscrypt_proxy_pidfile_tmp=\${${i}_pidfile} eval dnscrypt_proxy_logfile_tmp=\${${i}_logfile}: ${dnscrypt_proxy_uid_tmp:=_dnscrypt-proxy} # User to run daemon as: ${dnscrypt_proxy_resolver_tmp:=opendns} # resolver to use: ${dnscrypt_proxy_pidfile_tmp:=/var/run/${i}.pid} # Path to pid file: ${dnscrypt_proxy_logfile_tmp:=/var/log/${i}.log} # Path to log file command_args="-d -p ${dnscrypt_proxy_pidfile_tmp} -l ${dnscrypt_proxy_logfile_tmp} -u ${dnscrypt_proxy_uid_tmp} -R ${dnscrypt_proxy_resolver_tmp}" pidfile=${dnscrypt_proxy_pidfile_tmp} _rc_restart_done=false # workaround for: service dnscrypt-proxy restart run_rc_command "$1"done
[update]command:wget -O /usr/local/share/dnscrypt-proxy/dnscrypt-resolvers.csv https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v1/dnscrypt-resolvers.csv && /usr/local/etc/rc.d/dnscrypt-proxy restartparameters:type:scriptmessage:Updating dnscrypt-resolvers.csvdescription: Update dnscrypt-resolvers.csv
service configd restart