Yet Another SysAdmin

Local Unbound Setup

I thought it would make sense to run Unbound locally to cache my DNS queries - which can speedup DNS resolution quite a bit.
So, let’s get started!

Installing Unbound

Unbound is available on all major Linux distributions and on the various BSD’s. I use Debian in this case and install Unbound via apt.

$ sudo apt install unbound -y

Use the package manager of your choice to install Unbound. (pkg on FreeBSD for example or pacman on Arch Linux - Whatever you might have on hand)

That is literally it - we can now shift over to configuring Unbound.

Configuration fun

Under Debian (or Debian based distributions) you will find the needed configuration files under:

/etc/unbound/

You could move on the edit /etc/unbound/unbound.conf directly, but I will create a new configuration file under /etc/unbound/unbound.conf.d since files in this directory are included automatically (This also keeps the main configuration file clean).

/etc/unbound/unbound.conf.d/config.conf

NOTE: You can name the file any way you want. Just make sure it ends in *.conf.

We can now paste in the following directives:

server:
  username: "unbound"
  directory: "/etc/unbound"
  do-ip6: no
  interface: 127.0.0.1
  port: 53
  prefetch: yes

  verbosity: 1
  log-queries: yes
  log-replies: yes

  cache-max-ttl: 14400
  cache-min-ttl: 1200

  hide-identity: yes
  hide-version: yes

  domain-insecure: "seven.lan"

  forward-zone:
    name: "seven.lan."
    forward-addr: 10.0.5.50

  forward-zone:
    name: "."
    forward-addr: 10.0.5.50

EXPLANATION:

In my setup, I forward queries to a local Bind instance which runs as a authorative DNS server. This might be something you don’t need!
Make sure to leave out “domain-insecure” and the above listed “forward-zone” for my domain. You only need "." (All) as a forward zone with a public DNS (Which means all queries are forwarded to that DNS server)

Save the configuration file and restart Unbound.

$ sudo systemctl restart unbound"

Testing

Now that we have set up Unbound we need to make sure that it works actually.
Let’s first display the journal in one terminal tab and then do a query.

$ sudo journalctl -f -u unbound

And now, let’s test if all works

$ dig openbsd.org @127.0.0.1

We can see that from the output (Journal) the query was successful!

...
Dec 23 18:30:11 chaos unbound[1189013]: [1189013:0] info: 127.0.0.1 openbsd.org. A IN

Perfect, it works!

Conclusion

Setting up Unbound is quite simple for the most part.
This is by the way a very easy setup - Nothing complex or complicated. It sure makes sense to cache DNS queries to speedup the lookup process at a later time.

Have fun playing around with Unbound!

Stay Open!

#Dns #Cache #Unbound #Debian #Ubuntu #Domain