FreeBSD 11 Unbound DNS server

** Updated guide to use unbound from package instead of local_unbound **

So setting up an easy DNS server in FreeBSD? I did not find any recent and up to date guides on how to set up Unbound. After figuring out how, I figured I should post it here. Most of you guys properly allready know how. But hey, there must be someone in here that can use this.

FreeBSD 11 Unbound DNS server Guide

Posted Apr 18, 2017, 10:19 AM UTC · edited

149
a4qbfb•

The base system version of Unbound is only meant for use as a local caching forwarding resolver. If that's what you want, then all you need to do is enable it and the rc script will take care of the rest:

# echo local_unbound_enable=yes >/etc/rc.conf.d/local_unbound
# service local_unbound start

It will automatically use the resolvers you get from DHCP (or for a static configuration, whatever was already in /etc/resolv.conf) as forwarders. If those don't work or you don't trust them, you can specify other resolvers to use instead:

# echo local_unbound_resolvers=\"8.8.8.8 8.8.4.4\" >>/etc/rc.conf.d/local_unbound
# service local_unbound setup
# service local_unbound reload

If you want to set up a resolver for your entire network, use the ports version instead and place your configuration in /usr/local/etc/unbound.


ETA: OK, so technically you could do something like this:

# cat >/var/unbound/conf.d/clients.conf <<EOF
server:
      interface: 0.0.0.0
      access-control: 192.168.1.0/24 allow
EOF
# service unbound reload

and it would do what you want, and do it better than the example in your blog post. But don't let anyone know I told you.

4
[deleted]•

[deleted]

2
rhavenn•

Any particular reason you should use the ports one for a network? Base works fine and is covered by the FreeBSD security team.

1
peterwemm•

The primary difference between the ports version and the base version is that the ports one is compiled to use libevent, while the base system has a more basic built-in event multiplexor. In theory, the ports version should be able to handle much higher query throughput.

In the freebsd.org cluster we use the base unbound on every single machine, they forward to a site-specific ports-unbound resolver pool for caching and for special treatment by the firewalls to talk to the outside world.

This is overkill for most people but solves a few issues due to quirks in our network setup. (What quirks? We use vlans internally and each vlan treats the others as hostile with stateful packet filtering between them. This setup reduces firewall state thrashing for us.)

5
rhavenn•

Thanks for the info. I've been using the base version in my home network without issue for caching and forwarding requests to a local knot DNS local zone and that, obviously, doesn't have the load of a big network.

1
rainer_d•

Not sure if this is in the handbook somewhere - but maybe it should be pointed out in a comment in the first line of unbound.conf that the local_unbound is just that.

I like how the config-files are organized, BTW.

1
a4qbfb•

Any particular reason you should use the ports one for a network?

The local_unbound rc script might overwrite your configuration, for one. And it's not a complete installation.

2
thorgrotleOP•

Thank you for your suggestions, I have tested my config running on the unbound pkg instead. Works the same but without chance of being reset.

Also figured out to make blacklist ala hosts file. And made a script to automate that process. Will share when I get home

1
[deleted]•

[deleted]

1
moviuro•

Thanks for the quick guide. Why not put it on the FreeBSD wiki itself? I found one for e.g. letsencrypt

And also, shameless plug for my lying DNS file generator to block advertising and known-bad domains (e.g. for DNS server for a mobile phone over VPN) (it works for a variety of formats... enjoy).

1
a4qbfb•

shameless plug for my lying DNS file generator

You should look into RPZ instead.

1