Agenda: dns-dig-hands-on-2.txt

File dns-dig-hands-on-2.txt, 13.8 KB (added by admin, 6 years ago)
Line 
1DNS lab: dig, part 2
2
3Debugging nameservers using dig +norec
4
5You do NOT need to be root to run this exercise. NOTE: it is very good
6practice to put a trailing dot after every hostname - this prevents the
7default domain from `/etc/resolv.conf` being appended.
8
9This example: testing __www.tiscali.co.uk.__
10
11For this lab, we'll need to temporarily change your default nameserver,
12configured 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   
251. Make a query starting at a root nameserver
26
27The 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:
42uk.         172800  IN  NS  ns1.nic.uk.
43uk.         172800  IN  NS  ns2.nic.uk.
44uk.         172800  IN  NS  ns3.nic.uk.
45uk.         172800  IN  NS  ns4.nic.uk.
46uk.         172800  IN  NS  ns5.nic.uk.
47uk.         172800  IN  NS  ns6.nic.uk.
48uk.         172800  IN  NS  ns7.nic.uk.
49uk.         172800  IN  NS  nsa.nic.uk.
50uk.         172800  IN  NS  nsb.nic.uk.
51uk.         172800  IN  NS  nsc.nic.uk.
52uk.         172800  IN  NS  nsd.nic.uk.
53
54;; ADDITIONAL SECTION:
55ns1.nic.uk.     172800  IN  AAAA    2a01:40:1001:35::2
56ns1.nic.uk.     172800  IN  A   195.66.240.130
57ns2.nic.uk.     172800  IN  A   217.79.164.131
58ns3.nic.uk.     172800  IN  A   213.219.13.131
59ns4.nic.uk.     172800  IN  AAAA    2001:630:181:35::83
60ns4.nic.uk.     172800  IN  A   194.83.244.131
61ns5.nic.uk.     172800  IN  A   213.246.167.131
62ns6.nic.uk.     172800  IN  A   213.248.254.130
63ns7.nic.uk.     172800  IN  A   212.121.40.130
64nsa.nic.uk.     172800  IN  AAAA    2001:502:ad09::3
65nsa.nic.uk.     172800  IN  A   156.154.100.3
66nsb.nic.uk.     172800  IN  A   156.154.101.3
67nsc.nic.uk.     172800  IN  A   156.154.102.3
68nsd.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
76Note: We only got back NS records (plus some related information - the A
77records which correspond to those nameservers). This is a REFERRAL.
78
79In theory we should repeat this query for `b.root-servers.net`,
80`c.root-servers.net` ... and check we get the same answers. Occasionally
81you _might_ find inconsistencies between root servers, but it's rare.
82
832. 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
87random order; this doesn't matter because we are going to try every one
88anyway)
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
1023. 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
139Note: if a server is authoritative for both a domain and a subdomain, it
140will immediately return the result for the subdomain. This is OK. In this
141example, the same servers are authoritative for both `.uk` and `.co.uk`,
142so they can refer us immediately to the servers for `tiscali.co.uk`, taking
143us down two levels of the DNS hierarchy in one go.
144
145You can see here that we are getting another delegation, this time to two
146other nameservers:
147
148>     ns0.as9105.com
149>     ns0.tiscali.co.uk
150
1514. 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
191This time, instead of getting another delegation, we have found the answer
192we are looking for. Note that the nameservers are both giving authoritative
193answers (`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
195used to perform the query. (This second set of NS records are contained
196within the authoritative server itself, as opposed to the delegation from
197above)
198
199Hint: try this!
200
201    $ dig +nssearch tiscali.co.uk
202
2035. 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
2146. Now check the NS records themselves!
215---------------------------------------
216
217Notice that every NS record points to the NAME of a host, not an IP
218address. (It is illegal for an NS record to point at an IP address, it will
219not work at all)
220
221However, when we issued a command like `dig @ns0.as9105.com ...`, we were
222relying on dig converting this name to the correct IP address. In fact, we are
223doing 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
231Therefore, you need to start again and check every NS record you found,
232starting from the root again, in exactly the same way! This is tedious, and
233usually the top-level servers are right. But it's worth checking your
234country-level NS records and your own NS records.
235
236Example: 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
250Notice 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
252the machines listed in the 'authority section')
253
254This is not an error as long as the answer is correct - it's called a "glue
255record" which we'll explain later - but we need to continue downwards to
256find 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
285Now 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
294The meaning of NOERROR
295-----------------------
296
297You may have paid attention to the status: field of the dig output:
298
299status: NXDOMAIN
300or
301status: NOERROR
302
303NXDOMAIN means Non-eXistent Domain - it means: "Sorry, no data exists
304for the given NAME at all".  It basically means that there is no DNS data
305for 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
310tiscali.co.uk. No A record, no AAAA record, etc...
311
312Now, you may also have noticed that the ANSWER section can contain
3130 answers, but still, the queried server returns NOERROR, and not
314NXDOMAIN.
315
316Why is this ?
317
318Let's say for example that we want to know the IP address for
319www.tiscali.co.uk:
320
321    $ dig +norec @ns0.tiscali.co.uk. www.tiscali.co.uk. a
322
323So far so good - you should see:
324
325status: NOERROR
326ANSWER: 1
327
328Now, let's ask for a *different* type ("Resource Record Type, formally
329speaking):
330
331    $ dig +norec @ns0.tiscali.co.uk. www.tiscali.co.uk. txt
332
333Notice that we ask for a TXT record for the name "www.tiscali.co.uk."
334
335What do we get ?
336
337status: NOERROR
338ANSWER: 0
339
340How can this be ?
341
342NOERROR in this case means "Sorry, no data exists for the given NAME & TYPE
343requested". Aha! Here we're being told that there is no TXT record data for
344www.tiscali.co.uk - but there may be other data under other data types.
345
346Indeed, 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
352Therefore, a non-existent name (NXDOMAIN) or an empty answer (NOERROR,
353ANSWER: 0) is *still* an answer, and we need to remember (cache) this,
354as we'll see below.
355
356Negative answers
357----------------
358
359The non-existence of a RR is an important piece of information too. The
360response 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
371AA is set, but there is nothing in the answer apart from the SOA. The
372parameters in the SOA are used to work out how much negative caching is
373allowed.
374
375Meaning 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
394As well as the lack of 'AA' flag, a good way to spot cached answers
395is 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
407Other dig options
408------------------
409
410Other dig options you may want to try - use the manpage to find out what
411they do!
412
413dig +tcp
414dig +trace
415
416Try other options you find in the man page!
417
418
419Clean up
420--------
421
422Finally, when you're done, remember to restore your /etc/resolv.conf:
423
424nameserver 10.20.0.230
425