I followed the https://www.openbsd.org/faq/pf/example1.html to set up an unbound DNS nameserver on a box.

Question: how do I configure the unbound DNS server to also use the /etc/hosts file on the box? I have a few domains in it for adblocking and it resolvs them instead of just giving back

  • 1
    I suspect that you need to configure the system resolver to use /etc/hosts first, then the local DNS server. I don't know how to do that on OpenBSD, but on most GNU/Linux systems, you'd poke around in /etc/nsswitch.conf to change the resolver ordering. Chances that anything resembling a proper DNS server would consult /etc/hosts are slim. – a CVn Dec 10 '16 at 12:09
  • 1
    As others note, unbound will not use /etc/hosts. If you want to use DNS misdirection for adblocking, then configure your unbound.conf to claim to be authoritative for the offending domains, with local-data lines pointing to 127.x.x.x – user4556274 Dec 10 '16 at 16:51

On OpenBSD you need to add a line like this to /etc/resolv.conf:

lookup file bind

However, this affects only the gethostbyname(3) and gethostbyaddr(3) calls, not the unbound responses. That is, it takes effect only for programs that run on the machine itself. It won't work if other machines are configured to use unbound on the OpenBSD machine as a resolver. To deal with that you'll probably need a HTTP proxy.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.