2017-04-27 09:03:55 +02:00
|
|
|
#! /usr/bin/env bash
|
2015-07-06 01:39:54 +02:00
|
|
|
|
2019-09-22 15:38:22 +02:00
|
|
|
KEYS_DIR="/opt/encrypted-dns/etc/keys"
|
2016-08-25 00:42:13 +02:00
|
|
|
ZONES_DIR="/opt/unbound/etc/unbound/zones"
|
2015-07-12 14:52:07 +02:00
|
|
|
|
2019-05-16 17:47:33 +02:00
|
|
|
reserved=134217728
|
2019-08-05 16:13:56 +02:00
|
|
|
availableMemory=$((1024 * $( (grep -F MemAvailable /proc/meminfo || grep -F MemTotal /proc/meminfo) | sed 's/[^0-9]//g')))
|
2019-05-12 13:13:06 +02:00
|
|
|
if [ $availableMemory -le $((reserved * 2)) ]; then
|
2016-04-21 10:21:40 +02:00
|
|
|
echo "Not enough memory" >&2
|
2015-07-06 01:39:54 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-05-12 13:13:06 +02:00
|
|
|
availableMemory=$((availableMemory - reserved))
|
2019-10-26 22:22:46 +02:00
|
|
|
msg_cache_size=$((availableMemory / 4))
|
2019-05-12 13:13:06 +02:00
|
|
|
rr_cache_size=$((availableMemory / 3))
|
2015-07-06 01:39:54 +02:00
|
|
|
nproc=$(nproc)
|
2019-05-12 13:07:02 +02:00
|
|
|
if [ "$nproc" -gt 1 ]; then
|
2019-05-12 13:13:06 +02:00
|
|
|
threads=$((nproc - 1))
|
2015-07-06 01:39:54 +02:00
|
|
|
else
|
|
|
|
threads=1
|
|
|
|
fi
|
|
|
|
|
2015-07-12 14:52:07 +02:00
|
|
|
provider_name=$(cat "$KEYS_DIR/provider_name")
|
|
|
|
|
2015-07-06 01:39:54 +02:00
|
|
|
sed \
|
|
|
|
-e "s/@MSG_CACHE_SIZE@/${msg_cache_size}/" \
|
2015-07-12 14:52:07 +02:00
|
|
|
-e "s/@PROVIDER_NAME@/${provider_name}/" \
|
2015-07-06 01:39:54 +02:00
|
|
|
-e "s/@RR_CACHE_SIZE@/${rr_cache_size}/" \
|
|
|
|
-e "s/@THREADS@/${threads}/" \
|
2016-10-02 04:52:35 +02:00
|
|
|
-e "s#@ZONES_DIR@#${ZONES_DIR}#" \
|
2015-07-06 01:39:54 +02:00
|
|
|
> /opt/unbound/etc/unbound/unbound.conf << EOT
|
|
|
|
server:
|
|
|
|
verbosity: 1
|
|
|
|
num-threads: @THREADS@
|
2015-11-28 13:52:35 +01:00
|
|
|
interface: 127.0.0.1@553
|
2015-07-06 01:39:54 +02:00
|
|
|
so-reuseport: yes
|
2019-05-12 13:42:22 +02:00
|
|
|
edns-buffer-size: 1220
|
2015-07-06 01:39:54 +02:00
|
|
|
delay-close: 10000
|
|
|
|
cache-min-ttl: 60
|
|
|
|
cache-max-ttl: 86400
|
|
|
|
do-daemonize: no
|
|
|
|
username: "_unbound"
|
|
|
|
log-queries: no
|
|
|
|
hide-version: yes
|
|
|
|
identity: "DNSCrypt"
|
|
|
|
harden-short-bufsize: yes
|
|
|
|
harden-large-queries: yes
|
|
|
|
harden-glue: yes
|
|
|
|
harden-dnssec-stripped: yes
|
|
|
|
harden-below-nxdomain: yes
|
|
|
|
harden-referral-path: no
|
|
|
|
do-not-query-localhost: no
|
|
|
|
prefetch: yes
|
|
|
|
prefetch-key: yes
|
2019-05-28 00:07:43 +02:00
|
|
|
qname-minimisation: yes
|
2015-07-15 20:07:50 +02:00
|
|
|
ratelimit: 1000
|
2015-07-06 01:39:54 +02:00
|
|
|
rrset-roundrobin: yes
|
|
|
|
minimal-responses: yes
|
|
|
|
chroot: "/opt/unbound/etc/unbound"
|
|
|
|
directory: "/opt/unbound/etc/unbound"
|
|
|
|
auto-trust-anchor-file: "var/root.key"
|
|
|
|
num-queries-per-thread: 4096
|
|
|
|
outgoing-range: 8192
|
|
|
|
msg-cache-size: @MSG_CACHE_SIZE@
|
|
|
|
rrset-cache-size: @RR_CACHE_SIZE@
|
2015-07-12 14:54:26 +02:00
|
|
|
neg-cache-size: 4M
|
2016-12-16 08:53:46 +01:00
|
|
|
serve-expired: yes
|
2015-07-06 01:39:54 +02:00
|
|
|
access-control: 0.0.0.0/0 allow
|
|
|
|
access-control: ::0/0 allow
|
|
|
|
|
|
|
|
local-zone: "belkin." static
|
|
|
|
local-zone: "corp." static
|
|
|
|
local-zone: "domain." static
|
|
|
|
local-zone: "example." static
|
|
|
|
local-zone: "home." static
|
|
|
|
local-zone: "invalid." static
|
|
|
|
local-zone: "lan." static
|
|
|
|
local-zone: "local." static
|
|
|
|
local-zone: "localdomain." static
|
|
|
|
local-zone: "test." static
|
2015-07-12 14:52:07 +02:00
|
|
|
local-zone: "@PROVIDER_NAME@." refuse
|
2015-11-28 12:59:25 +01:00
|
|
|
|
2016-08-25 00:42:13 +02:00
|
|
|
include: "@ZONES_DIR@/*.conf"
|
2016-08-24 22:36:21 +02:00
|
|
|
|
2015-11-28 12:59:25 +01:00
|
|
|
remote-control:
|
|
|
|
control-enable: yes
|
|
|
|
control-interface: 127.0.0.1
|
2015-07-06 01:39:54 +02:00
|
|
|
EOT
|
|
|
|
|
2019-08-05 16:13:56 +02:00
|
|
|
mkdir -p /opt/unbound/etc/unbound/dev &&
|
|
|
|
cp -a /dev/random /dev/urandom /opt/unbound/etc/unbound/dev/
|
2015-07-06 01:39:54 +02:00
|
|
|
|
2019-08-05 16:13:56 +02:00
|
|
|
mkdir -p -m 700 /opt/unbound/etc/unbound/var &&
|
|
|
|
chown _unbound:_unbound /opt/unbound/etc/unbound/var &&
|
|
|
|
/opt/unbound/sbin/unbound-anchor -a /opt/unbound/etc/unbound/var/root.key
|
2015-07-06 01:39:54 +02:00
|
|
|
|
2015-11-28 13:19:39 +01:00
|
|
|
if [ ! -f /opt/unbound/etc/unbound/unbound_control.pem ]; then
|
2019-10-01 19:55:57 +02:00
|
|
|
/opt/unbound/sbin/unbound-control-setup 2> /dev/null || :
|
2015-11-28 13:19:39 +01:00
|
|
|
fi
|
|
|
|
|
2016-08-25 00:42:13 +02:00
|
|
|
mkdir -p /opt/unbound/etc/unbound/zones
|
|
|
|
|
2015-07-06 01:39:54 +02:00
|
|
|
exec /opt/unbound/sbin/unbound
|