Use your Synology as a local DNS cache

It is totally unnecessary to have all your computers, iPad’s and iPhone’s ask your router to resolve domain names to an external DNS server whenever you click a link or enter a domain name.

Why not have something that sits on your local network and forwards unknown DNS requests and then saves the cache so the next time that request would take ≈ 1 ms instead of ≈ 50 ms (or ever more if you use your ISP’s DNS service)?

You can use a Raspberry Pi to do this as well (let me know if you want a post on how to do that) but since I have a Synology RackStation at home, I’ll use that instead.

First of all, I click to en Synology Package Center and installed a package call ‘DNS server’.

dns

After that I entered the settings page for the DNS server and activated it as well as activated forwarding to Googles DNS servers. Here you can enter anyones you want. I find Google’s fast and reliable.

settings

And then I adjusted some of the size settings.

size

Just to try it out I did a series of 30 parallell queries on a domain on my computer.

Type this in your terminal to query your current DNS 30 times for oskarhane.com and print the average time.

for i in {1..30}; do echo oskarhane.com;done | xargs -I^ -P10 dig ^ | grep time | awk /time/'{sum+=$4} END { print "Average query = ",sum/NR,"ms"}'

I got Average query = 51,1333 ms going straight to Google’s DNS servers.

To test the Synology I entered Network Settings on my Mac and entered the local ip to my Synology as the DNS server to use.

network

And then I ran the test again, this time getting Average query = 23,3 ms. Cut by half, but remember, the first query is not cached so that probably took at least 50 ms!.

Running the query once more should return just cached responses.

Average query = 1,1 ms

Indeed, this is fast!

Anyway, if I just leave it with this and take my computer outside my home network, I’m not going to be able to resolve any domains since my computer won’t be able to find my local DNS server.

So, remove the ip to the Synology in the network settings no the mac (leave it empty, defaulting to the current router/gateway).

I want to efter this in my routers settings so everyone on my home network gets tt benefit from this.

I have an Apple Airport Extreme (which actually has a DNS cache itself so this will not have any impact) so I start the app Airport Utility and enter the local ip to my Synology in BOTH DNS server IP fields.

Refer to your router’s manual on how to change DNS server settings.

All done.