If you re looking for a pcap only solution, you re going to have to intercept the DNS request packet, examine it, and assemble the proper reply before the DNS server replies. That doesn t seem real reliable because if the DNS server has an entry cached it s likely to reply before your custom code to assemble a packet and send it out can finish.
The most reliable way to do this is to write a kernel module that is a netfilter hook. Netfilter hooks are able to examine a packet and influence the handling of it at several points before a packet leaves a machine. Hook it at the NF_IP_LOCAL_OUT level. You can then examine the outgoing packet and see if it is a DNS reply fitting your criteria. This next part I haven t done, but since you have direct access to the skb (socket buffer) as an input parameter to your custom hook function, you could modify the packet right there and return NF_ACCEPT to pass the response along to the client. If you needed to do some processing on the request itself, you could hook into NF_IP_LOCAL_IN instead and handle it any number of ways including passing it off to a userspace program.
There are many examples on Google for Linux kernel programming (search: Linux Kernel Module Programming) and also netfilter hook examples.