-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Replace bind9 with unbound #2193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
9548289
2ef097e
70e842f
e56cb44
dcf1b0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
server: | ||
# the working directory. | ||
directory: "/etc/unbound" | ||
|
||
# run as the unbound user | ||
username: unbound | ||
|
||
verbosity: 0 # uncomment and increase to get more logging. | ||
# logfile: "/var/log/unbound.log" # won't work due to apparmor | ||
# use-syslog: no | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coming back to this PR... Is unbound logging to somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's logging to the systemd journal and to the syslog. |
||
|
||
# By default listen only to localhost | ||
#interface: ::1 | ||
#interface: 127.0.0.1 | ||
port: 53 | ||
|
||
# Only allow localhost to use this Unbound instance. | ||
access-control: 127.0.0.1/8 allow | ||
access-control: ::1/128 allow | ||
|
||
# Private IP ranges, which shall never be returned or forwarded as public DNS response. | ||
private-address: 10.0.0.0/8 | ||
private-address: 172.16.0.0/12 | ||
private-address: 192.168.0.0/16 | ||
private-address: 169.254.0.0/16 | ||
private-address: fd00::/8 | ||
private-address: fe80::/10 | ||
|
||
# Functionality | ||
do-ip4: yes | ||
do-ip6: yes | ||
do-udp: yes | ||
do-tcp: yes | ||
|
||
# Performance | ||
num-threads: 2 | ||
cache-min-ttl: 300 | ||
cache-max-ttl: 86400 | ||
serve-expired: yes | ||
neg-cache-size: 4M | ||
msg-cache-size: 50m | ||
rrset-cache-size: 100m | ||
|
||
so-reuseport: yes | ||
so-rcvbuf: 4m | ||
so-sndbuf: 4m | ||
|
||
# Privacy / hardening | ||
# hide server info from clients | ||
hide-identity: yes | ||
hide-version: yes | ||
harden-glue: yes | ||
harden-dnssec-stripped: yes | ||
harden-algo-downgrade: yes | ||
harden-large-queries: yes | ||
harden-short-bufsize: yes | ||
|
||
rrset-roundrobin: yes | ||
minimal-responses: yes | ||
identity: "Server" | ||
|
||
# Include possible white/blacklists | ||
include: /etc/unbound/lists.d/*.conf | ||
|
||
remote-control: | ||
control-enable: yes | ||
control-port: 953 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,45 +314,42 @@ fi #NODOC | |
# DNS server, which won't work for RBLs. So we really need a local recursive | ||
# nameserver. | ||
# | ||
# We'll install `bind9`, which as packaged for Ubuntu, has DNSSEC enabled by default via "dnssec-validation auto". | ||
# We'll install unbound, which as packaged for Ubuntu, has DNSSEC enabled by default. | ||
# We'll have it be bound to 127.0.0.1 so that it does not interfere with | ||
# the public, recursive nameserver `nsd` bound to the public ethernet interfaces. | ||
# | ||
# About the settings: | ||
# | ||
# * Adding -4 to OPTIONS will have `bind9` not listen on IPv6 addresses | ||
# so that we're sure there's no conflict with nsd, our public domain | ||
# name server, on IPV6. | ||
# * The listen-on directive in named.conf.options restricts `bind9` to | ||
# binding to the loopback interface instead of all interfaces. | ||
# * The max-recursion-queries directive increases the maximum number of iterative queries. | ||
# If more queries than specified are sent, bind9 returns SERVFAIL. After flushing the cache during system checks, | ||
# we ran into the limit thus we are increasing it from 75 (default value) to 100. | ||
apt_install bind9 | ||
tools/editconf.py /etc/default/named \ | ||
"OPTIONS=\"-u bind -4\"" | ||
if ! grep -q "listen-on " /etc/bind/named.conf.options; then | ||
# Add a listen-on directive if it doesn't exist inside the options block. | ||
sed -i "s/^}/\n\tlisten-on { 127.0.0.1; };\n}/" /etc/bind/named.conf.options | ||
fi | ||
if ! grep -q "max-recursion-queries " /etc/bind/named.conf.options; then | ||
# Add a max-recursion-queries directive if it doesn't exist inside the options block. | ||
sed -i "s/^}/\n\tmax-recursion-queries 100;\n}/" /etc/bind/named.conf.options | ||
|
||
# remove bind9 in case it is still there | ||
apt-get purge -qq -y bind9 bind9-utils | ||
|
||
# Install unbound and dns utils (e.g. dig) | ||
apt_install unbound python3-unbound bind9-dnsutils | ||
|
||
|
||
# Configure unbound | ||
cp -f conf/unbound.conf /etc/unbound/unbound.conf.d/miabunbound.conf | ||
|
||
mkdir -p /etc/unbound/lists.d | ||
|
||
systemctl restart unbound | ||
|
||
unbound-control -q status | ||
|
||
# Only reset the local dns settings if unbound server is running, otherwise we'll | ||
# up with a system with an unusable internet connection | ||
if [ $? -ne 0 ]; then | ||
echo "Recursive DNS server not active" | ||
exit 1 | ||
fi | ||
|
||
# First we'll disable systemd-resolved's management of resolv.conf and its stub server. | ||
# Breaking the symlink to /run/systemd/resolve/stub-resolv.conf means | ||
# systemd-resolved will read it for DNS servers to use. Put in 127.0.0.1, | ||
# which is where bind9 will be running. Obviously don't do this before | ||
# installing bind9 or else apt won't be able to resolve a server to | ||
# download bind9 from. | ||
# Modify systemd settings | ||
rm -f /etc/resolv.conf | ||
tools/editconf.py /etc/systemd/resolved.conf DNSStubListener=no | ||
tools/editconf.py /etc/systemd/resolved.conf \ | ||
DNS=127.0.0.1 \ | ||
DNSSEC=yes \ | ||
DNSStubListener=no | ||
echo "nameserver 127.0.0.1" > /etc/resolv.conf | ||
|
||
# Restart the DNS services. | ||
|
||
restart_service bind9 | ||
systemctl restart systemd-resolved | ||
|
||
# ### Fail2Ban Service | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How different is this from the stock configuration file when ubound is installed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A number of the options here are indeed the default for a stock configuration. The main differences are probably in the performance and hardening settings.
Some testing seems to confirm the unbound configuration will work out of the box.