Configuring OpenWRT and OpenDNS to log all DNS lookups

Why log all DNS lookups?

  1. To list websites visited by you or any computer served by your router
  2. To assist in identifying presence of malware


This tutorial is for OpenWRT Chaos Calmer. However, with slight tweaks and understanding the gist of the setup described here, you should be able to get this to work with other versions.

You also need an account at DNS-O-Matic, a free service by OpenDNS. The reason is described below.

How it works

I believe that most public DNS servers log lookups whether they publicly declare or say nothing about. Why? For gathering analytics (market research), to curb abuses, etc.

OpenDNS is a free public DNS service provider. They have logging feature with log records view-able by you but some configuration is required to get this to work.

In order for OpenDNS to gather these details on your behalf, you must inform them of your current IP address so that it can log and correlate to you. Why? No user identity information is attached to DNS query payloads so correlating to your current IP address is the simplest method. The process of updating OpenDNS can be automated using OpenWRT.


OpenDNS DNS-O-Matic setup

Firstly, we need an account on DNS-O-Matic and OpenDNS to maintain logs.

  1. Signup for a DNS-O-Matic account. Use a password without special characters. As far as I remember, this caused issues with configuration on OpenWRT. You can compensate the loss of password strength by increasing length.
  2. Using the same login credentials, signin at
  3. Under Settings, label your network with a name. I call it ‘Home’
  4. Settings for: <Your network label>, select this
  5. Click on Stats and Logs
  6. Enable stats and logs
  7. Go back to DNS-O-Matic
  8. Add a service, OpenDNS
  9. Select your home network

OpenWRT configuration

We need to configure OpenWRT to update OpenDNS via DNS-O-Matic service upon change of public IP address, i.e. due to reboot of router, WAN link dropped and reconnected, etc.

Note: These steps are for OpenWRT Chaos Calmer.

Important: Depending on available space on your router, you may have to resort to using non-SSL options.

  1. Navigate to System > Software
  2. Update lists
  3. If you want to use SSL, install ca-certificates and wget
  4. If you do not want to or unable to use SSL, install wget-nossl
  5. Install ddns-scripts and luci-app-ddns
  6. Navigate to Service > Dynamic DNS
  7. Add a new entry and call it dnsomatic
  8. Select -custom- DDNS Service provider
  9. Set Custom update-url to http://[USERNAME]:[PASSWORD][IP]&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG without substituting anything
  10. Set hostname to
  11. Enter your username and password
  12. Check ‘Use HTTP Secure’ if you are using the SSL option
  13. The [IP] part of the URL will be substituted as defined by ‘IP address source ‘and ‘Network’ fields under ‘Advanced Settings’.
  14. Save & Apply


Login into DNS-O-Matic. You should be able to see the current IP address and history of updates. The IP should be the same as what you see on What Is My IP. In a couple of hours, DNS statistics should appear on your ‘OpenDNS Dashboard’ under Stats.

Redirect all DNS lookups (Optional)

The router’s DHCP server should have assigned itself as the DNS server to all DHCP clients on your network. However, one may deliberately choose to perform lookups on a different server. If you want to log every DNS lookup, you have to redirect all DNS queries to the router’s DNS forwarder.

In OpenWrt, navigate to Network > Firewall > Custom Rules. Add the following lines:

# Redirect DNS requests to go through router
iptables -t nat -A PREROUTING -i br-lan -p udp --dport 53 -j REDIRECT --to-port 53

Note: This requires iptables package to be installed.

Be sure to replace br-lan with your LAN interface name in case different.

To test, configure your computer to utilise Google DNS. Then visit where this page will tell you if you are on OpenDNS, which you should be.