1
1
mirror of https://github.com/dnscrypt/dnscrypt-server-docker synced 2024-11-22 23:51:59 +01:00
dnscrypt-server-docker/unbound.sh

103 lines
2.7 KiB
Bash
Raw Normal View History

#! /usr/bin/env bash
2015-07-06 01:39:54 +02:00
KEYS_DIR="/opt/encrypted-dns/etc/keys"
ZONES_DIR="/opt/unbound/etc/unbound/zones"
reserved=134217728
availableMemory=$((1024 * $( (grep -F MemAvailable /proc/meminfo || grep -F MemTotal /proc/meminfo) | sed 's/[^0-9]//g')))
if [ $availableMemory -le $((reserved * 2)) ]; then
echo "Not enough memory" >&2
2015-07-06 01:39:54 +02:00
exit 1
fi
availableMemory=$((availableMemory - reserved))
2019-10-26 22:22:46 +02:00
msg_cache_size=$((availableMemory / 4))
rr_cache_size=$((availableMemory / 3))
2015-07-06 01:39:54 +02:00
nproc=$(nproc)
if [ "$nproc" -gt 1 ]; then
threads=$((nproc - 1))
2015-07-06 01:39:54 +02:00
else
threads=1
fi
provider_name=$(cat "$KEYS_DIR/provider_name")
2015-07-06 01:39:54 +02:00
sed \
-e "s/@MSG_CACHE_SIZE@/${msg_cache_size}/" \
-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}/" \
-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@
interface: 127.0.0.1@553
2015-07-06 01:39:54 +02:00
so-reuseport: yes
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
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
local-zone: "@PROVIDER_NAME@." refuse
2015-11-28 12:59:25 +01:00
include: "@ZONES_DIR@/*.conf"
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
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
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
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 || :
fi
mkdir -p /opt/unbound/etc/unbound/zones
2015-07-06 01:39:54 +02:00
exec /opt/unbound/sbin/unbound