1 | DNS lab: dig, part 2 |
---|
2 | |
---|
3 | Debugging nameservers using dig +norec |
---|
4 | |
---|
5 | You do NOT need to be root to run this exercise. NOTE: it is very good |
---|
6 | practice to put a trailing dot after every hostname - this prevents the |
---|
7 | default domain from `/etc/resolv.conf` being appended. |
---|
8 | |
---|
9 | This example: testing __www.tiscali.co.uk.__ |
---|
10 | |
---|
11 | For this lab, we'll need to temporarily change your default nameserver, |
---|
12 | configured in /etc/resolv.conf, to 10.20.0.254, like so: |
---|
13 | |
---|
14 | # ee /etc/resolv.conf |
---|
15 | |
---|
16 | ... and set the nameserver to be: |
---|
17 | |
---|
18 | nameserver 10.20.0.254 |
---|
19 | |
---|
20 | Save the file and exit the editor. |
---|
21 | |
---|
22 | Note: we need to do this, otherwise we won't be able to lookup names |
---|
23 | on the Internet! |
---|
24 | |
---|
25 | 1. Make a query starting at a root nameserver |
---|
26 | |
---|
27 | The root servers are called `[a-m].root-servers.net.` - pick any one to start. |
---|
28 | |
---|
29 | $ dig +norec @f.root-servers.net www.tiscali.co.uk. a |
---|
30 | |
---|
31 | ; <<>> DiG 9.7.2-P3 <<>> +norec @a.root-servers.net. www.tiscali.co.uk. a |
---|
32 | ; (2 servers found) |
---|
33 | ;; global options: +cmd |
---|
34 | ;; Got answer: |
---|
35 | ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8712 |
---|
36 | ;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 11, ADDITIONAL: 14 |
---|
37 | |
---|
38 | ;; QUESTION SECTION: |
---|
39 | ;www.tiscali.co.uk. IN A |
---|
40 | |
---|
41 | ;; AUTHORITY SECTION: |
---|
42 | uk. 172800 IN NS ns1.nic.uk. |
---|
43 | uk. 172800 IN NS ns2.nic.uk. |
---|
44 | uk. 172800 IN NS ns3.nic.uk. |
---|
45 | uk. 172800 IN NS ns4.nic.uk. |
---|
46 | uk. 172800 IN NS ns5.nic.uk. |
---|
47 | uk. 172800 IN NS ns6.nic.uk. |
---|
48 | uk. 172800 IN NS ns7.nic.uk. |
---|
49 | uk. 172800 IN NS nsa.nic.uk. |
---|
50 | uk. 172800 IN NS nsb.nic.uk. |
---|
51 | uk. 172800 IN NS nsc.nic.uk. |
---|
52 | uk. 172800 IN NS nsd.nic.uk. |
---|
53 | |
---|
54 | ;; ADDITIONAL SECTION: |
---|
55 | ns1.nic.uk. 172800 IN AAAA 2a01:40:1001:35::2 |
---|
56 | ns1.nic.uk. 172800 IN A 195.66.240.130 |
---|
57 | ns2.nic.uk. 172800 IN A 217.79.164.131 |
---|
58 | ns3.nic.uk. 172800 IN A 213.219.13.131 |
---|
59 | ns4.nic.uk. 172800 IN AAAA 2001:630:181:35::83 |
---|
60 | ns4.nic.uk. 172800 IN A 194.83.244.131 |
---|
61 | ns5.nic.uk. 172800 IN A 213.246.167.131 |
---|
62 | ns6.nic.uk. 172800 IN A 213.248.254.130 |
---|
63 | ns7.nic.uk. 172800 IN A 212.121.40.130 |
---|
64 | nsa.nic.uk. 172800 IN AAAA 2001:502:ad09::3 |
---|
65 | nsa.nic.uk. 172800 IN A 156.154.100.3 |
---|
66 | nsb.nic.uk. 172800 IN A 156.154.101.3 |
---|
67 | nsc.nic.uk. 172800 IN A 156.154.102.3 |
---|
68 | nsd.nic.uk. 172800 IN A 156.154.103.3 |
---|
69 | |
---|
70 | ;; Query time: 8 msec |
---|
71 | ;; SERVER: 198.41.0.4#53(198.41.0.4) |
---|
72 | ;; WHEN: Tue Feb 15 15:53:13 2011 |
---|
73 | ;; MSG SIZE rcvd: 497 |
---|
74 | |
---|
75 | |
---|
76 | Note: We only got back NS records (plus some related information - the A |
---|
77 | records which correspond to those nameservers). This is a REFERRAL. |
---|
78 | |
---|
79 | In theory we should repeat this query for `b.root-servers.net`, |
---|
80 | `c.root-servers.net` ... and check we get the same answers. Occasionally |
---|
81 | you _might_ find inconsistencies between root servers, but it's rare. |
---|
82 | |
---|
83 | 2. Note the eleven nameservers we saw in the response |
---|
84 | ----------------------------------------------------- |
---|
85 | |
---|
86 | (Remember that DNS names are not case sensitive. We also get them back in a |
---|
87 | random order; this doesn't matter because we are going to try every one |
---|
88 | anyway) |
---|
89 | |
---|
90 | ns1.nic.uk. |
---|
91 | ns2.nic.uk. |
---|
92 | ns3.nic.uk. |
---|
93 | ns4.nic.uk. |
---|
94 | ns5.nic.uk. |
---|
95 | ns6.nic.uk. |
---|
96 | ns7.nic.uk. |
---|
97 | nsa.nic.uk. |
---|
98 | nsb.nic.uk. |
---|
99 | nsc.nic.uk. |
---|
100 | nsd.nic.uk. |
---|
101 | |
---|
102 | 3. Repeat the query for all NS records in turn |
---|
103 | ---------------------------------------------- |
---|
104 | |
---|
105 | $ dig +norec @ns1.nic.uk. www.tiscali.co.uk. a |
---|
106 | |
---|
107 | ; <<>> DiG 9.7.2-P3 <<>> +norec @ns1.nic.uk. www.tiscali.co.uk. a |
---|
108 | ; (1 server found) |
---|
109 | ;; global options: printcmd |
---|
110 | ;; Got answer: |
---|
111 | ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28452 |
---|
112 | ;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 2, ADDITIONAL: 1 |
---|
113 | |
---|
114 | ;; QUESTION SECTION: |
---|
115 | ;www.tiscali.co.uk. IN A |
---|
116 | |
---|
117 | ;; AUTHORITY SECTION: |
---|
118 | tiscali.co.uk. 172800 IN NS ns0.as9105.com. |
---|
119 | tiscali.co.uk. 172800 IN NS ns0.tiscali.co.uk. |
---|
120 | |
---|
121 | ;; ADDITIONAL SECTION: |
---|
122 | ns0.tiscali.co.uk. 172800 IN A 212.74.114.132 |
---|
123 | |
---|
124 | ;; Query time: 20 msec |
---|
125 | ;; SERVER: 195.66.240.130#53(195.66.240.130) |
---|
126 | ;; WHEN: Mon May 16 12:37:23 2005 |
---|
127 | ;; MSG SIZE rcvd: 97 |
---|
128 | |
---|
129 | |
---|
130 | $ dig +norec @ns2.nic.uk. www.tiscali.co.uk. a |
---|
131 | ... |
---|
132 | |
---|
133 | $ dig +norec @ns3.nic.uk. www.tiscali.co.uk. a |
---|
134 | ... |
---|
135 | ... etc |
---|
136 | |
---|
137 | *Check that the results are consistent!* |
---|
138 | |
---|
139 | Note: if a server is authoritative for both a domain and a subdomain, it |
---|
140 | will immediately return the result for the subdomain. This is OK. In this |
---|
141 | example, the same servers are authoritative for both `.uk` and `.co.uk`, |
---|
142 | so they can refer us immediately to the servers for `tiscali.co.uk`, taking |
---|
143 | us down two levels of the DNS hierarchy in one go. |
---|
144 | |
---|
145 | You can see here that we are getting another delegation, this time to two |
---|
146 | other nameservers: |
---|
147 | |
---|
148 | > ns0.as9105.com |
---|
149 | > ns0.tiscali.co.uk |
---|
150 | |
---|
151 | 4. Continue to repeat the query for all NS records found in step 3 |
---|
152 | ------------------------------------------------------------------ |
---|
153 | |
---|
154 | $ dig +norec @ns0.tiscali.co.uk. www.tiscali.co.uk. a |
---|
155 | |
---|
156 | ; <<>> DiG 9.7.2-P3 <<>> +norec @ns0.tiscali.co.uk. www.tiscali.co.uk. a |
---|
157 | ; (1 server found) |
---|
158 | ;; global options: +cmd |
---|
159 | ;; Got answer: |
---|
160 | ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52841 |
---|
161 | ;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2 |
---|
162 | |
---|
163 | ;; QUESTION SECTION: |
---|
164 | ;www.tiscali.co.uk. IN A |
---|
165 | |
---|
166 | ;; ANSWER SECTION: |
---|
167 | www.tiscali.co.uk. 300 IN A 212.74.99.30 |
---|
168 | |
---|
169 | ;; AUTHORITY SECTION: |
---|
170 | tiscali.co.uk. 3600 IN NS ns0.tiscali.co.uk. |
---|
171 | tiscali.co.uk. 3600 IN NS ns0.as9105.com. |
---|
172 | |
---|
173 | ;; ADDITIONAL SECTION: |
---|
174 | ns0.as9105.com. 604800 IN A 212.139.129.130 |
---|
175 | ns0.tiscali.co.uk. 604800 IN A 212.74.114.132 |
---|
176 | |
---|
177 | ;; Query time: 322 msec |
---|
178 | ;; SERVER: 212.74.114.132#53(212.74.114.132) |
---|
179 | ;; WHEN: Tue Feb 15 16:01:04 2011 |
---|
180 | ;; MSG SIZE rcvd: 129 |
---|
181 | |
---|
182 | |
---|
183 | $ dig +norec @ns0.as9105.com. www.tiscali.co.uk. a |
---|
184 | ... |
---|
185 | ;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2 |
---|
186 | ... |
---|
187 | ;; ANSWER SECTION: |
---|
188 | www.tiscali.co.uk. 300 IN A 212.74.99.30 |
---|
189 | |
---|
190 | |
---|
191 | This time, instead of getting another delegation, we have found the answer |
---|
192 | we are looking for. Note that the nameservers are both giving authoritative |
---|
193 | answers (`flags: aa`), and the results are the same. Also note that the |
---|
194 | 'AUTHORITY SECTION' in the response has the *same* list of nameservers as we |
---|
195 | used to perform the query. (This second set of NS records are contained |
---|
196 | within the authoritative server itself, as opposed to the delegation from |
---|
197 | above) |
---|
198 | |
---|
199 | Hint: try this! |
---|
200 | |
---|
201 | $ dig +nssearch tiscali.co.uk |
---|
202 | |
---|
203 | 5. Checklist |
---|
204 | ------------ |
---|
205 | |
---|
206 | * Were all the nameservers reachable? |
---|
207 | * Were there at least two nameservers on two different subnets? |
---|
208 | * Did they all give either a referral or an AA (Authoritative Answer)? |
---|
209 | * Were all the answers the same? |
---|
210 | * Were the TTL values reasonable? |
---|
211 | * Does the final list of nameservers in the AUTHORITY SECTION match the |
---|
212 | list of nameservers in the referral? |
---|
213 | |
---|
214 | 6. Now check the NS records themselves! |
---|
215 | --------------------------------------- |
---|
216 | |
---|
217 | Notice that every NS record points to the NAME of a host, not an IP |
---|
218 | address. (It is illegal for an NS record to point at an IP address, it will |
---|
219 | not work at all) |
---|
220 | |
---|
221 | However, when we issued a command like `dig @ns0.as9105.com ...`, we were |
---|
222 | relying on dig converting this name to the correct IP address. In fact, we are |
---|
223 | doing two queries: |
---|
224 | |
---|
225 | - dig asks for the IP address of ns0.as9105.com, performing a recursive |
---|
226 | lookup using the nameserver listeed in /etc/resolv.conf |
---|
227 | |
---|
228 | - once dig has gotten the IP address of the nameserver, dig can send its |
---|
229 | query to that server |
---|
230 | |
---|
231 | Therefore, you need to start again and check every NS record you found, |
---|
232 | starting from the root again, in exactly the same way! This is tedious, and |
---|
233 | usually the top-level servers are right. But it's worth checking your |
---|
234 | country-level NS records and your own NS records. |
---|
235 | |
---|
236 | Example: check ns0.as9105.com |
---|
237 | |
---|
238 | $ dig +norec @a.root-servers.net. ns0.as9105.com. a |
---|
239 | ... referral to [a-m].gtld-servers.net. |
---|
240 | |
---|
241 | $ dig +norec @a.gtld-servers.net. ns0.as9105.com. a |
---|
242 | ;; flags: qr; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1 |
---|
243 | ;; ANSWER SECTION: |
---|
244 | ns0.as9105.com. 172800 IN A 212.139.129.130 <==== |
---|
245 | |
---|
246 | ;; AUTHORITY SECTION: |
---|
247 | as9105.com. 172800 IN NS ns0.as9105.com. |
---|
248 | as9105.com. 172800 IN NS ns0.tiscali.co.uk. |
---|
249 | |
---|
250 | Notice that here we got an answer - but it is not an authoritative answer! |
---|
251 | (As well as 'aa' missing, notice that the machine we queried is not one of |
---|
252 | the machines listed in the 'authority section') |
---|
253 | |
---|
254 | This is not an error as long as the answer is correct - it's called a "glue |
---|
255 | record" which we'll explain later - but we need to continue downwards to |
---|
256 | find the true authoritative source: |
---|
257 | |
---|
258 | $ dig +norec @ns0.as9105.com. ns0.as9105.com. a |
---|
259 | ;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1 |
---|
260 | |
---|
261 | ;; ANSWER SECTION: |
---|
262 | ns0.as9105.com. 2419200 IN A 212.139.129.130 <==== |
---|
263 | |
---|
264 | ;; AUTHORITY SECTION: |
---|
265 | as9105.com. 600 IN NS ns0.tiscali.co.uk. |
---|
266 | as9105.com. 600 IN NS ns0.as9105.com. |
---|
267 | |
---|
268 | ;; ADDITIONAL SECTION: |
---|
269 | ns0.tiscali.co.uk. 2419200 IN A 212.74.114.132 |
---|
270 | |
---|
271 | |
---|
272 | $ dig +norec @ns0.tiscali.co.uk. ns0.as9105.com. a |
---|
273 | ;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1 |
---|
274 | |
---|
275 | ;; ANSWER SECTION: |
---|
276 | ns0.as9105.com. 2419200 IN A 212.139.129.130 <==== |
---|
277 | |
---|
278 | ;; AUTHORITY SECTION: |
---|
279 | as9105.com. 600 IN NS ns0.tiscali.co.uk. |
---|
280 | as9105.com. 600 IN NS ns0.as9105.com. |
---|
281 | |
---|
282 | ;; ADDITIONAL SECTION: |
---|
283 | ns0.tiscali.co.uk. 2419200 IN A 212.74.114.132 |
---|
284 | |
---|
285 | Now we check: |
---|
286 | |
---|
287 | * Were all the answers the same? (Yes: 212.139.129.130 from both |
---|
288 | `a.gtld-servers.net` and the authoritative nameservers) |
---|
289 | * Did the delegation match the NS records in the authoritative |
---|
290 | nameservers? (Yes: delegation to `ns0.as9105.com` and |
---|
291 | `ns0.tiscali.co.uk`, and these records were also given in the |
---|
292 | 'authority section' of the final response) |
---|
293 | |
---|
294 | The meaning of NOERROR |
---|
295 | ----------------------- |
---|
296 | |
---|
297 | You may have paid attention to the status: field of the dig output: |
---|
298 | |
---|
299 | status: NXDOMAIN |
---|
300 | or |
---|
301 | status: NOERROR |
---|
302 | |
---|
303 | NXDOMAIN means Non-eXistent Domain - it means: "Sorry, no data exists |
---|
304 | for the given NAME at all". It basically means that there is no DNS data |
---|
305 | for the name you're querying. For instance: |
---|
306 | |
---|
307 | $ dig +norec @ns0.tiscali.co.uk. wibble.tiscali.co.uk. a |
---|
308 | |
---|
309 | ... will return NXDOMAIN. There is nothing at all for "wibble" under |
---|
310 | tiscali.co.uk. No A record, no AAAA record, etc... |
---|
311 | |
---|
312 | Now, you may also have noticed that the ANSWER section can contain |
---|
313 | 0 answers, but still, the queried server returns NOERROR, and not |
---|
314 | NXDOMAIN. |
---|
315 | |
---|
316 | Why is this ? |
---|
317 | |
---|
318 | Let's say for example that we want to know the IP address for |
---|
319 | www.tiscali.co.uk: |
---|
320 | |
---|
321 | $ dig +norec @ns0.tiscali.co.uk. www.tiscali.co.uk. a |
---|
322 | |
---|
323 | So far so good - you should see: |
---|
324 | |
---|
325 | status: NOERROR |
---|
326 | ANSWER: 1 |
---|
327 | |
---|
328 | Now, let's ask for a *different* type ("Resource Record Type, formally |
---|
329 | speaking): |
---|
330 | |
---|
331 | $ dig +norec @ns0.tiscali.co.uk. www.tiscali.co.uk. txt |
---|
332 | |
---|
333 | Notice that we ask for a TXT record for the name "www.tiscali.co.uk." |
---|
334 | |
---|
335 | What do we get ? |
---|
336 | |
---|
337 | status: NOERROR |
---|
338 | ANSWER: 0 |
---|
339 | |
---|
340 | How can this be ? |
---|
341 | |
---|
342 | NOERROR in this case means "Sorry, no data exists for the given NAME & TYPE |
---|
343 | requested". Aha! Here we're being told that there is no TXT record data for |
---|
344 | www.tiscali.co.uk - but there may be other data under other data types. |
---|
345 | |
---|
346 | Indeed, we know from earlier that: |
---|
347 | |
---|
348 | $ dig +norec @ns0.tiscali.co.uk. www.tiscali.co.uk. a |
---|
349 | |
---|
350 | ... will return us the IP address of www.tiscali.co.uk. |
---|
351 | |
---|
352 | Therefore, a non-existent name (NXDOMAIN) or an empty answer (NOERROR, |
---|
353 | ANSWER: 0) is *still* an answer, and we need to remember (cache) this, |
---|
354 | as we'll see below. |
---|
355 | |
---|
356 | Negative answers |
---|
357 | ---------------- |
---|
358 | |
---|
359 | The non-existence of a RR is an important piece of information too. The |
---|
360 | response you get should look like this: |
---|
361 | |
---|
362 | $ dig +norec @ns0.tiscali.co.uk. wibble.tiscali.co.uk. a |
---|
363 | ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 51165 |
---|
364 | ;; flags: qr aa; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0 |
---|
365 | |
---|
366 | ;; AUTHORITY SECTION: |
---|
367 | tiscali.co.uk. 3600 IN SOA ns0.tiscali.co.uk. hostmaster.talktalkplc.com. |
---|
368 | 2011012703 10800 3600 604800 3600 |
---|
369 | |
---|
370 | |
---|
371 | AA is set, but there is nothing in the answer apart from the SOA. The |
---|
372 | parameters in the SOA are used to work out how much negative caching is |
---|
373 | allowed. |
---|
374 | |
---|
375 | Meaning of flags (from RFC 1034/RFC 1035) |
---|
376 | ----------------------------------------- |
---|
377 | |
---|
378 | QR A one bit field that specifies whether this message is a |
---|
379 | query (0), or a response (1). |
---|
380 | |
---|
381 | AA Authoritative Answer - this bit is valid in responses, |
---|
382 | and specifies that the responding name server is an |
---|
383 | authority for the domain name in question section. |
---|
384 | |
---|
385 | RD Recursion Desired - this bit may be set in a query and |
---|
386 | is copied into the response. If RD is set, it directs |
---|
387 | the name server to pursue the query recursively. |
---|
388 | Recursive query support is optional. |
---|
389 | |
---|
390 | RA Recursion Available - this be is set or cleared in a |
---|
391 | response, and denotes whether recursive query support is |
---|
392 | available in the name server. |
---|
393 | |
---|
394 | As well as the lack of 'AA' flag, a good way to spot cached answers |
---|
395 | is to repeat the query a few times and watch the TTL counting downwards. |
---|
396 | |
---|
397 | $ dig psg.com. |
---|
398 | ;; ANSWER SECTION: |
---|
399 | psg.com. 14397 IN A 147.28.0.62 |
---|
400 | ^^^^^ |
---|
401 | $ dig psg.com. |
---|
402 | ;; ANSWER SECTION: |
---|
403 | psg.com. 14384 IN A 147.28.0.62 |
---|
404 | ^^^^^ |
---|
405 | |
---|
406 | |
---|
407 | Other dig options |
---|
408 | ------------------ |
---|
409 | |
---|
410 | Other dig options you may want to try - use the manpage to find out what |
---|
411 | they do! |
---|
412 | |
---|
413 | dig +tcp |
---|
414 | dig +trace |
---|
415 | |
---|
416 | Try other options you find in the man page! |
---|
417 | |
---|
418 | |
---|
419 | Clean up |
---|
420 | -------- |
---|
421 | |
---|
422 | Finally, when you're done, remember to restore your /etc/resolv.conf: |
---|
423 | |
---|
424 | nameserver 10.20.0.230 |
---|
425 | |
---|