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

7 Answers 7


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

  • 10
    Any details on how?
    – e-sushi
    Commented Feb 5, 2016 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. Commented Apr 5, 2017 at 16:04
  • 1
    github.com/gamelinux/passivedns seems to be doing just that, see ./doc/How-it-works.txt
    – mxmlnkn
    Commented Jan 12, 2018 at 21:10
  • 15
    tcpdump udp port 53
    – Brannon
    Commented Mar 13, 2018 at 4:48
  • 3
    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 Commented May 17, 2019 at 20:08

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:


UPDATE (2023): output format of tcpdump changed; domain name is in field #9, not #8.

Fixed one-liner:

script -q -c "sudo tcpdump -l port 53 2>/dev/null | grep --line-buffered ' A? ' | cut -d' ' -f9" | tee dns.log
  • 1
    This command worked for me, but I don't understand why script is needed. Could you explain?
    – Dagang
    Commented Jul 16, 2021 at 17:39
  • Will print responses with implicit request info on a single line: sudo tcpdump -vvli eth0 port 53 | grep --line-buffered " q: A? " | cut -d' ' -f16-
    – Matteljay
    Commented Aug 27, 2021 at 12:52
  • This just prints out a bunch of lines that say A?
    – Herohtar
    Commented Jan 18, 2023 at 15:29
  • 2
    @Herohtar the output format of tcpdump has been changed. Now domain name is in field #9, not #8. Try script -q -c "sudo tcpdump -l port 53 2>/dev/null | grep --line-buffered ' A? ' | cut -d' ' -f9" | tee dns.log
    – Vanni
    Commented Jan 19, 2023 at 0:18

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 or ::1 as the DNS resolver.

  • 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
    Commented Jul 23, 2012 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
    Commented Jul 23, 2012 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
    Commented Jul 23, 2012 at 15:19

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


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


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.


Please try PassiveDNS - A tool to collect DNS records passively to aid Incident handling, Network Security Monitoring (NSM) and general digital forensics.

To make it simple to use, I created a docker image called vimagick/passivedns

version: "3.8"
    image: vimagick/passivedns
    command: >
      -d "||"
      -i eth0
      -l /var/log/passivedns/passivedns.log
      -L /var/log/passivedns/passivedns-nx.log
      -p /var/run/passivedns.pid
      -P 86400
      -S 256
      -X 46CDNOPRSTMnx
      - ./data:/var/log/passivedns
    network_mode: host
    privileged: true
    restart: unless-stopped

Up and running:

# assume your iface name is eth0
$ ifconfig eth0

$ mkdir passivedns
$ cd passivedns

# paste yaml content here
$ vim docker-compose.yml

$ docker compose up -d

$ tail -f data/passivedns.log

Example output:

#timestamp||dns-client ||dns-server||RR class||Query||Query Type||Answer||TTL||Count

You must log in to answer this question.