Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I spent hours today trying to figure out why my own socket-level implementation of DIG in a browser is not working consistently. I would successfully send a DNS packet over UDP but would receive a response without an answer section. It would sometimes work but then would suddenly stop working without any code changes. After pulling out Wireshark, I saw the following two images (one via Dig which succeeded and the other, performed by my web-app, not).

enter image description here

enter image description here

share|improve this question
up vote 0 down vote accepted

The key that I noticed is in the one bit for whether recursion is desired. As per and RFC 1035 at page 25:

Recursion Desired - this bit may be set in a query and is copied into the response.
If RD is set, it directs the name server to pursue the query recursively.
Recursive query support is optional."

At first, I didn't think this bit was the source of the problem as I sometimes received the right response without the bit set (i.e., with 0 for recursion). The explanation is that if a resolver has a result cached, it will return it even with 0 for recursion.

After some playing around at the command-line, I simulated my behavior with Dig by passing the "+norecurse" flag:

$ dig mx @ +norecurse

; <<>> DiG 9.8.3-P1 <<>> mx @ +norecurse
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62530
;; flags: qr ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

;            IN  MX

;; Query time: 50 msec
;; WHEN: Mon Dec 24 19:52:23 2012
;; MSG SIZE  rcvd: 28

I then removed the +norecurse and everything worked fine!

Lesson: If you are not seeing any answer section to your DNS requests, check whether you are performing a recursive query. Chances are you are not and there are no cached results with your resolver you are querying, so you get nothing back.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .