DNS Caching

This tutorial shows how to setup DNS caching on the Raspberry Pi With Arch Linux ARM and dnsmasq. This quide is based on my default Raspberry Pi setup. You might want to checkout that guide first to get everything working.

DNS caching can speed up browsing a bit, for me however it doesn't make a huge difference but it's a fun little project for a spare Raspberry Pi.

1. Install DNSmasq

Install DNSmasq with the following command:

sudo pacman -S dnsmasq

2. Configure dnsmasq

Remove the /etc/dnsmasq.conf and create a new one with following content:

# Dnsmasq.conf for raspberry pi
# /etc/dnsmasq.conf
# http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq.conf.example

# Set up your local domain here

# Max cache size dnsmasq can give us, and we want all of it!

# Below are settings for dhcp. Comment them out if you dont want
# dnsmasq to serve up dhcpd requests.
# dhcp-range=,,,1440m
# dhcp-option=3,
# dhcp-authoritative

3. Enable and start the dnsmasq service

Enable the dnsmasq service with the following commands:

sudo systemctl enable dnsmasq
sudo systemctl start dnsmasq

The DNS caching is now setup up and ready to use. You can now point your computers or even easier your router to the Raspberry Pi.

4. Testing (optional)

If you want to test if it's working you can use the tool "dig". It's part of the bind-tools package.

Install it with:

sudo pacman -S bind-tools

Then you can execute this command:

dig archlinux.org | grep "Query time"

Instead of archlinux.org you can use any url you want. With this tool you can check the query time for your current DNS server.

Without DNS caching I have query times usually ranging from 150ms to 8ms. While values of over 100ms are usually for sites which get visited the first time. With a Raspberry Pi as a DNS cache I get values ranging from 50ms to 1ms while values around 50ms are the first look up.


Websites used to create this tutorial:

No Comments
Back to top