Skip to main content.

Encrypting DNS lookups


Live demo in BSD Now Episode 039 | Originally written by TJ for | Last updated: 2015/06/30

NOTE: the author/maintainer of the tutorial(s) is no longer with the show, so the information below may be outdated or incorrect.

We briefly set up DNSCrypt in the OpenBSD router guide, but this tutorial will show you how to do it for any regular desktop or server system. This will also explain in a little more detail about what's actually happening and why you might want to use it. So, why would you want to encrypt your DNS lookups? Probably because DNS is a horrible, insecure system. It has no authentication, and can be spoofed very easily at any point in the connection. DNSSEC helps try to solve this problem, but it's not in very wide deployment right now. DNSSEC and DNSCrypt go hand in hand, complimenting each other. Even if you choose a "good" server, any of the hops between you and that server can take over and redirect your queries. Once they've done so, they could even do horrible things like redirect to Imagine trying to go to this website to learn about security, but being redirected to a website promoting buggy software! Don't let this nightmarish situation happen to you - keep your DNS secure. The tool we'll be highlighting today is called dnscrypt-proxy, and it was originally developed by OpenDNS. There are versions for lots of operating systems, and all the BSDs should have a native port or package available. After installing it from your favorite source, we'll set it up for a single desktop or server system. If you want to run it on your entire network, which is probably the best way, consult the OpenBSD router tutorial linked above. Combining dnscrypt-proxy with a caching resolver like BIND or Unbound is an ideal setup. The port will not do any caching by itself, so every lookup has to make a round trip to the DNS server. That takes more time and more bandwidth, so consider using it with a caching resolver on your gateway. Let's first have a look at what files were included with the software. On OpenBSD:

$ pkg_info -L dnscrypt-proxy

Information for inst:dnscrypt-proxy-1.3.3


Or on the simpler FreeBSD port,

$ pkg info -l dnscrypt-proxy


In both cases it includes the daemon binary, some man pages and an rc.d script for autostarting. Once you've read over the man page, we can tell dnscrypt-proxy to start up automatically. You can use the included rc.d scripts with your BSD of choice's methods, but I'll provide a generic way that should work for everyone.

# vi /etc/rc.local

We'll add a line like this:

/usr/local/sbin/dnscrypt-proxy -a -R -u _dnscrypt-proxy -l /dev/null -d

In this case, "_dnscrypt-proxy" is the name of the unprivileged user. We tell the daemon to listen on localhost, port 53, and to send all its logs to /dev/null. They're worthless anyway. We also want to daemonize the script so it's always running in the background. It's possible to run it in the foreground, possibly in tmux. After we have that in place, let's tell our system to use our local resolver instead of whatever you were using before.

# echo "nameserver" > /etc/resolv.conf

Depending on your network settings and whether you're using DHCP, this file may get overwritten automatically with other DNS servers. You can change that behavior in your DHCP client's configuration file, usually located at /etc/dhclient.conf. Alternatively, you can take a forceful approach and lock the file from all changes:

# chflags schg /etc/resolv.conf

Now we can start up the service using the same command we added to rc.local:

# dnscrypt-proxy -a -R -u _dnscrypt-proxy -l /dev/null -d

All your DNS lookups should now be encrypted. We can test it by checking a domain name like so:

$ nslookup


Non-authoritative answer:

As long as it says "Server:" then you are indeed using the local resolver. If you're using pf as your firewall, you can block all "normal" DNS lookups from leaking by using the example in that tutorial. That's good to fall back on in case something was misconfigured somewhere else. There is a list of other DNSCrypt-capable servers on the homepage. The man page for dnscrypt-proxy will show you how to switch to another server. It's probably a good idea to use one close to your physical location for low latency.

Latest News

New announcement


Hi, Mr. Dexter...

Two Year Anniversary


We're quickly approaching our two-year anniversary, which will be on episode 105. To celebrate, we've created a unique t-shirt design, available for purchase until the end of August. Shirts will be shipped out around September 1st. Most of the proceeds will support the show, and specifically allow us to buy...

New discussion segment


We're thinking about adding a new segment to the show where we discuss a topic that the listeners suggest. It's meant to be informative like a tutorial, but more of a "free discussion" format. If you have any subjects you want us to explore, or even just a good name...

How did you get into BSD?


We've got a fun idea for the holidays this year: just like we ask during the interviews, we want to hear how all the viewers and listeners first got into BSD. Email us your story, either written or a video version, and we'll read and play some of them for...

Episode 210: Your questions, part I


Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines A Reimplementation Of Netbsd Using a Microkernel Minix author Andy Tanenbaum writes in Part 1 of a-reimplementation-of-netbsd-using-a-microkernel Based on the MINIX 3 microkernel, we have constructed a system that to the user looks a great deal like NetBSD. It uses pkgsrc,...

Episode 209: Signals: gotta catch ‘em all


Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines Trip Report: FreeBSD in China at COPU and LinuxCon This trip report is from Deb Goodkin, the Executive Director of the FreeBSD Foundation. She travelled to China in May 2017 to promote FreeBSD, meet with companies, and participate in discussions around Open...

Episode 208: Faces of Open Source


Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines LLVM, Clang and compiler-rt support enhancements In the last month I started with upstream of the code for sanitizers: the common layer and ubsan. I worked also on the elimination of unexpected failures in LLVM and Clang. I've managed to...

Episode 207: Bridge over the river Cam


Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines BSDCam recap The 2017 Cambridge DevSummit took place from 2-4 August 2017. The event took place over three days including a formal dinner at St John's College, and was attended by 55 registered developers and guests. Prior to the start of...