19

How can I create logs of every DNS query that my computer makes along with the responses it gets?

14

You can have tcpdump log all port 53 UDP and TCP activity.

| improve this answer | |
  • 6
    Any details on how? – e-sushi Feb 5 '16 at 17:57
  • This is the best answer as we can't be sure the OP (or other readers) have access to the DNS server - only their local machine. To answer @e-sushi's question take a tcpdump using the utility (check out the man page or a good primer with examples). Your best bet is to dump to a file and then pull that data into wireshark for review & analysis. – James Shewey Apr 5 '17 at 16:04
  • 1
    github.com/gamelinux/passivedns seems to be doing just that, see ./doc/How-it-works.txt – mxmlnkn Jan 12 '18 at 21:10
  • 5
    tcpdump udp port 53 – Brannon Mar 13 '18 at 4:48
  • 1
    It may not select the outbound network interface by default, so you need a bit more: tcpdump --list-interfaces, tcpdump udp port 53 --interface (pickone). Also consider verbosity: -vv – nobar May 17 '19 at 20:08
9

The easiest way is to install Bind locally. Most distros default install of Bind will be non-autoritative caching-only.

Simply add a logging {} config block (as described in the Bind 9 Configuration Reference) then set your system to use 127.0.0.1 or ::1 as the DNS resolver.

| improve this answer | |
  • 2
    Given how large bind is and its lackluster security record, I think many people would hesitate to install something like that for the sole purpose of logging. – jw013 Jul 23 '12 at 1:16
  • doesn't bind have the issue that the nameservers in /etc/resolv.conf are not used but nameservers must be listed explicitly in the bind config? – Bananguin Jul 23 '12 at 7:12
  • No. /etc/resolv.conf is the system resolver list. Bind's default configuration is to look up the authoritative name servers and ask them. You could forward all requests to a specific server (or set, such as your ISP, OpenDNS or Google Public DNS) but it's not required to do so in the config. I do this all the time. I can't even count the number of times I've set up caching only name servers. – bahamat Jul 23 '12 at 15:19
6

dnsmasq is far easier to configure as a DNS aggregator/caching daemon than BIND, and for that purpose, the performance might just be better. If you turn logging up to "debug", all the questions and answers show up in whatever syslog has configured for debug messages.

Dnsmasq also makes it easy to get rid of abusive advertisers and dirtbag privacy invading "analytic" creeps by aliasing entire domains to 127.0.0.1

| improve this answer | |
3

To show and save to file all the A DNS requests, run this:

script -q -c "sudo tcpdump -l port 53 2>/dev/null | grep --line-buffered ' A? ' | cut -d' ' -f8" | tee dns.log

Example output:

google.com.
wikipedia.org.

| improve this answer | |
1

If I recall correctly Snort can selectively monitor traffic based on user defined rules. However, Snort will not create logs for DNS requests when your computer, i.e. its resolver, can answer the question from its cache.

| improve this answer | |
0

One easy way to filter the DNS , for the requests you are interested in is to grep the next row too grep -A 2 where -A is after and 2 rows after . If the server has a lot of DNS requests increase from 2 to 4-5

tcpdump -l port 53 |grep -A 2  redis

the second line will be the answer from DNS -> IP, CNAME ,none , other

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy