| 1 | Exercise 2.1: Debugging nameservers using dig +norec |
|---|
| 2 | ==================================================== |
|---|
| 3 | |
|---|
| 4 | You do NOT need to be root to run this exercise. NOTE: it is very good |
|---|
| 5 | practice to put a trailing dot after every hostname - this prevents the |
|---|
| 6 | default domain from `/etc/resolv.conf` being appended. |
|---|
| 7 | |
|---|
| 8 | This example: testing __www.tiscali.co.uk.__ |
|---|
| 9 | |
|---|
| 10 | 1. Make a query starting at a root nameserver |
|---|
| 11 | --------------------------------------------- |
|---|
| 12 | |
|---|
| 13 | The root servers are called `[a-m].root-servers.net.` - pick any one to |
|---|
| 14 | start. |
|---|
| 15 | |
|---|
| 16 | $ dig +norec @a.root-servers.net. www.tiscali.co.uk. a |
|---|
| 17 | |
|---|
| 18 | ; <<>> DiG 9.7.2-P3 <<>> +norec @a.root-servers.net. www.tiscali.co.uk. a |
|---|
| 19 | ; (2 servers found) |
|---|
| 20 | ;; global options: +cmd |
|---|
| 21 | ;; Got answer: |
|---|
| 22 | ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8712 |
|---|
| 23 | ;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 11, ADDITIONAL: 14 |
|---|
| 24 | |
|---|
| 25 | ;; QUESTION SECTION: |
|---|
| 26 | ;www.tiscali.co.uk. IN A |
|---|
| 27 | |
|---|
| 28 | ;; AUTHORITY SECTION: |
|---|
| 29 | uk. 172800 IN NS ns1.nic.uk. |
|---|
| 30 | uk. 172800 IN NS ns2.nic.uk. |
|---|
| 31 | uk. 172800 IN NS ns3.nic.uk. |
|---|
| 32 | uk. 172800 IN NS ns4.nic.uk. |
|---|
| 33 | uk. 172800 IN NS ns5.nic.uk. |
|---|
| 34 | uk. 172800 IN NS ns6.nic.uk. |
|---|
| 35 | uk. 172800 IN NS ns7.nic.uk. |
|---|
| 36 | uk. 172800 IN NS nsa.nic.uk. |
|---|
| 37 | uk. 172800 IN NS nsb.nic.uk. |
|---|
| 38 | uk. 172800 IN NS nsc.nic.uk. |
|---|
| 39 | uk. 172800 IN NS nsd.nic.uk. |
|---|
| 40 | |
|---|
| 41 | ;; ADDITIONAL SECTION: |
|---|
| 42 | ns1.nic.uk. 172800 IN AAAA 2a01:40:1001:35::2 |
|---|
| 43 | ns1.nic.uk. 172800 IN A 195.66.240.130 |
|---|
| 44 | ns2.nic.uk. 172800 IN A 217.79.164.131 |
|---|
| 45 | ns3.nic.uk. 172800 IN A 213.219.13.131 |
|---|
| 46 | ns4.nic.uk. 172800 IN AAAA 2001:630:181:35::83 |
|---|
| 47 | ns4.nic.uk. 172800 IN A 194.83.244.131 |
|---|
| 48 | ns5.nic.uk. 172800 IN A 213.246.167.131 |
|---|
| 49 | ns6.nic.uk. 172800 IN A 213.248.254.130 |
|---|
| 50 | ns7.nic.uk. 172800 IN A 212.121.40.130 |
|---|
| 51 | nsa.nic.uk. 172800 IN AAAA 2001:502:ad09::3 |
|---|
| 52 | nsa.nic.uk. 172800 IN A 156.154.100.3 |
|---|
| 53 | nsb.nic.uk. 172800 IN A 156.154.101.3 |
|---|
| 54 | nsc.nic.uk. 172800 IN A 156.154.102.3 |
|---|
| 55 | nsd.nic.uk. 172800 IN A 156.154.103.3 |
|---|
| 56 | |
|---|
| 57 | ;; Query time: 8 msec |
|---|
| 58 | ;; SERVER: 198.41.0.4#53(198.41.0.4) |
|---|
| 59 | ;; WHEN: Tue Feb 15 15:53:13 2011 |
|---|
| 60 | ;; MSG SIZE rcvd: 497 |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | Note: We only got back NS records (plus some related information - the A |
|---|
| 64 | records which correspond to those nameservers). This is a REFERRAL. |
|---|
| 65 | |
|---|
| 66 | In theory we should repeat this query for `b.root-servers.net`, |
|---|
| 67 | `c.root-servers.net` ... and check we get the same answers. Occasionally |
|---|
| 68 | you _might_ find inconsistencies between root servers, but it's rare. |
|---|
| 69 | |
|---|
| 70 | 2. Note the eleven nameservers we saw in the response |
|---|
| 71 | ----------------------------------------------------- |
|---|
| 72 | |
|---|
| 73 | (Remember that DNS names are not case sensitive. We also get them back in a |
|---|
| 74 | random order; this doesn't matter because we are going to try every one |
|---|
| 75 | anyway) |
|---|
| 76 | |
|---|
| 77 | ns1.nic.uk. |
|---|
| 78 | ns2.nic.uk. |
|---|
| 79 | ns3.nic.uk. |
|---|
| 80 | ns4.nic.uk. |
|---|
| 81 | ns5.nic.uk. |
|---|
| 82 | ns6.nic.uk. |
|---|
| 83 | ns7.nic.uk. |
|---|
| 84 | nsa.nic.uk. |
|---|
| 85 | nsb.nic.uk. |
|---|
| 86 | nsc.nic.uk. |
|---|
| 87 | nsd.nic.uk. |
|---|
| 88 | |
|---|
| 89 | 3. Repeat the query for all NS records in turn |
|---|
| 90 | ---------------------------------------------- |
|---|
| 91 | |
|---|
| 92 | $ dig +norec @ns1.nic.uk. www.tiscali.co.uk. a |
|---|
| 93 | |
|---|
| 94 | ; <<>> DiG 9.7.2-P3 <<>> +norec @ns1.nic.uk. www.tiscali.co.uk. a |
|---|
| 95 | ; (1 server found) |
|---|
| 96 | ;; global options: printcmd |
|---|
| 97 | ;; Got answer: |
|---|
| 98 | ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28452 |
|---|
| 99 | ;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 2, ADDITIONAL: 1 |
|---|
| 100 | |
|---|
| 101 | ;; QUESTION SECTION: |
|---|
| 102 | ;www.tiscali.co.uk. IN A |
|---|
| 103 | |
|---|
| 104 | ;; AUTHORITY SECTION: |
|---|
| 105 | tiscali.co.uk. 172800 IN NS ns0.as9105.com. |
|---|
| 106 | tiscali.co.uk. 172800 IN NS ns0.tiscali.co.uk. |
|---|
| 107 | |
|---|
| 108 | ;; ADDITIONAL SECTION: |
|---|
| 109 | ns0.tiscali.co.uk. 172800 IN A 212.74.114.132 |
|---|
| 110 | |
|---|
| 111 | ;; Query time: 20 msec |
|---|
| 112 | ;; SERVER: 195.66.240.130#53(195.66.240.130) |
|---|
| 113 | ;; WHEN: Mon May 16 12:37:23 2005 |
|---|
| 114 | ;; MSG SIZE rcvd: 97 |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | $ dig +norec @ns2.nic.uk. www.tiscali.co.uk. a |
|---|
| 118 | ... results snipped to save paper |
|---|
| 119 | |
|---|
| 120 | $ dig +norec @ns3.nic.uk. www.tiscali.co.uk. a |
|---|
| 121 | ... results snipped to save paper |
|---|
| 122 | ... etc |
|---|
| 123 | |
|---|
| 124 | *Check the results are consistent!* |
|---|
| 125 | |
|---|
| 126 | Note: if a server is authoritative for both a domain and a subdomain, it |
|---|
| 127 | will immediately return the result for the subdomain. This is OK. In this |
|---|
| 128 | example, the same servers are authoritative for both `.uk` and `.co.uk`, |
|---|
| 129 | so they can delegate us immediately to the servers for `tiscali.co.uk`, taking |
|---|
| 130 | us down two levels of the DNS hierarchy in one go. |
|---|
| 131 | |
|---|
| 132 | You can see here that we are getting another delegation, this time to two |
|---|
| 133 | other nameservers: |
|---|
| 134 | |
|---|
| 135 | > ns0.as9105.com |
|---|
| 136 | > ns0.tiscali.co.uk |
|---|
| 137 | |
|---|
| 138 | 4. Continue to repeat the query for all NS records found in step 3 |
|---|
| 139 | ------------------------------------------------------------------ |
|---|
| 140 | |
|---|
| 141 | $ dig +norec @ns0.tiscali.co.uk. www.tiscali.co.uk. a |
|---|
| 142 | |
|---|
| 143 | ; <<>> DiG 9.7.2-P3 <<>> +norec @ns0.tiscali.co.uk. www.tiscali.co.uk. a |
|---|
| 144 | ; (1 server found) |
|---|
| 145 | ;; global options: +cmd |
|---|
| 146 | ;; Got answer: |
|---|
| 147 | ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52841 |
|---|
| 148 | ;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2 |
|---|
| 149 | |
|---|
| 150 | ;; QUESTION SECTION: |
|---|
| 151 | ;www.tiscali.co.uk. IN A |
|---|
| 152 | |
|---|
| 153 | ;; ANSWER SECTION: |
|---|
| 154 | www.tiscali.co.uk. 300 IN A 212.74.99.30 |
|---|
| 155 | |
|---|
| 156 | ;; AUTHORITY SECTION: |
|---|
| 157 | tiscali.co.uk. 3600 IN NS ns0.tiscali.co.uk. |
|---|
| 158 | tiscali.co.uk. 3600 IN NS ns0.as9105.com. |
|---|
| 159 | |
|---|
| 160 | ;; ADDITIONAL SECTION: |
|---|
| 161 | ns0.as9105.com. 604800 IN A 212.139.129.130 |
|---|
| 162 | ns0.tiscali.co.uk. 604800 IN A 212.74.114.132 |
|---|
| 163 | |
|---|
| 164 | ;; Query time: 322 msec |
|---|
| 165 | ;; SERVER: 212.74.114.132#53(212.74.114.132) |
|---|
| 166 | ;; WHEN: Tue Feb 15 16:01:04 2011 |
|---|
| 167 | ;; MSG SIZE rcvd: 129 |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | $ dig +norec @ns0.as9105.com. www.tiscali.co.uk. a |
|---|
| 171 | ... |
|---|
| 172 | ;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2 |
|---|
| 173 | ... |
|---|
| 174 | ;; ANSWER SECTION: |
|---|
| 175 | www.tiscali.co.uk. 300 IN A 212.74.99.30 |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | This time, instead of getting another delegation, we have found the answer |
|---|
| 179 | we are looking for. Note that the nameservers are both giving authoritative |
|---|
| 180 | answers (`flags: aa`), and the results are the same. Also note that the |
|---|
| 181 | 'AUTHORITY SECTION' in the response has the *same* list of nameservers as we |
|---|
| 182 | used to perform the query. (This second set of NS records are contained |
|---|
| 183 | within the authoritative server itself, as opposed to the delegation from |
|---|
| 184 | above) |
|---|
| 185 | |
|---|
| 186 | 5. Checklist |
|---|
| 187 | ------------ |
|---|
| 188 | |
|---|
| 189 | * Were all the nameservers reachable? |
|---|
| 190 | * Were there at least two nameservers on two different subnets? |
|---|
| 191 | * Did they all give either a referral or an AA (Authoritative Answer)? |
|---|
| 192 | * Were all the answers the same? |
|---|
| 193 | * Were the TTL values reasonable? |
|---|
| 194 | * Does the final list of nameservers in the AUTHORITY SECTION match the |
|---|
| 195 | list of nameservers in the referral? |
|---|
| 196 | |
|---|
| 197 | 6. Now check the NS records themselves! |
|---|
| 198 | --------------------------------------- |
|---|
| 199 | |
|---|
| 200 | Notice that every NS record points to the NAME of a host, not an IP |
|---|
| 201 | address. (It is illegal for an NS record to point at an IP address, it will |
|---|
| 202 | not work at all) |
|---|
| 203 | |
|---|
| 204 | However, when we issued a command like `dig @ns0.as9105.com ...`, we were |
|---|
| 205 | relying on dig converting this name to the correct IP address. It performs a |
|---|
| 206 | recursive lookup to find the IP address of this server, so that it can send |
|---|
| 207 | the query there. |
|---|
| 208 | |
|---|
| 209 | Therefore, you need to start again and check every NS record you found, |
|---|
| 210 | starting from the root again, in exactly the same way! This is tedious, and |
|---|
| 211 | usually the top-level servers are right. But it's worth checking your |
|---|
| 212 | country-level NS records and your own NS records. |
|---|
| 213 | |
|---|
| 214 | Example: check ns0.as9105.com |
|---|
| 215 | |
|---|
| 216 | $ dig +norec @a.root-servers.net. ns0.as9105.com. a |
|---|
| 217 | ... referral to [a-m].gtld-servers.net. |
|---|
| 218 | |
|---|
| 219 | $ dig +norec @a.gtld-servers.net. ns0.as9105.com. a |
|---|
| 220 | ;; flags: qr; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1 |
|---|
| 221 | ;; ANSWER SECTION: |
|---|
| 222 | ns0.as9105.com. 172800 IN A 212.139.129.130 <==== |
|---|
| 223 | |
|---|
| 224 | ;; AUTHORITY SECTION: |
|---|
| 225 | as9105.com. 172800 IN NS ns0.as9105.com. |
|---|
| 226 | as9105.com. 172800 IN NS ns0.tiscali.co.uk. |
|---|
| 227 | |
|---|
| 228 | Notice that here we got an answer - but it is not an authoritative answer! |
|---|
| 229 | (As well as 'aa' missing, notice that the machine we queried is not one of |
|---|
| 230 | the machines listed in the 'authority section') |
|---|
| 231 | |
|---|
| 232 | This is not an error as long as the answer is correct - it's called a "glue |
|---|
| 233 | record" which we'll discuss later - but we need to continue downwards to |
|---|
| 234 | find the true authoritative source: |
|---|
| 235 | |
|---|
| 236 | $ dig +norec @ns0.as9105.com. ns0.as9105.com. a |
|---|
| 237 | ;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1 |
|---|
| 238 | |
|---|
| 239 | ;; ANSWER SECTION: |
|---|
| 240 | ns0.as9105.com. 2419200 IN A 212.139.129.130 <==== |
|---|
| 241 | |
|---|
| 242 | ;; AUTHORITY SECTION: |
|---|
| 243 | as9105.com. 600 IN NS ns0.tiscali.co.uk. |
|---|
| 244 | as9105.com. 600 IN NS ns0.as9105.com. |
|---|
| 245 | |
|---|
| 246 | ;; ADDITIONAL SECTION: |
|---|
| 247 | ns0.tiscali.co.uk. 2419200 IN A 212.74.114.132 |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | $ dig +norec @ns0.tiscali.co.uk. ns0.as9105.com. a |
|---|
| 251 | ;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1 |
|---|
| 252 | |
|---|
| 253 | ;; ANSWER SECTION: |
|---|
| 254 | ns0.as9105.com. 2419200 IN A 212.139.129.130 <==== |
|---|
| 255 | |
|---|
| 256 | ;; AUTHORITY SECTION: |
|---|
| 257 | as9105.com. 600 IN NS ns0.tiscali.co.uk. |
|---|
| 258 | as9105.com. 600 IN NS ns0.as9105.com. |
|---|
| 259 | |
|---|
| 260 | ;; ADDITIONAL SECTION: |
|---|
| 261 | ns0.tiscali.co.uk. 2419200 IN A 212.74.114.132 |
|---|
| 262 | |
|---|
| 263 | Now we check: |
|---|
| 264 | |
|---|
| 265 | * Were all the answers the same? (Yes: 212.139.129.130 from both |
|---|
| 266 | `a.gtld-servers.net` and the authoritative nameservers) |
|---|
| 267 | * Did the delegation match the NS records in the authoritative |
|---|
| 268 | nameservers? (Yes: delegation to `ns0.as9105.com` and |
|---|
| 269 | `ns0.tiscali.co.uk`, and these records were also given in the |
|---|
| 270 | 'authority section' of the final response) |
|---|
| 271 | |
|---|
| 272 | Negative answers |
|---|
| 273 | ---------------- |
|---|
| 274 | |
|---|
| 275 | The non-existence of a RR is an important piece of information too. The |
|---|
| 276 | response you get should look like this: |
|---|
| 277 | |
|---|
| 278 | $ dig +norec @ns0.tiscali.co.uk. wibble.tiscali.co.uk. a |
|---|
| 279 | ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 51165 |
|---|
| 280 | ;; flags: qr aa; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0 |
|---|
| 281 | |
|---|
| 282 | ;; AUTHORITY SECTION: |
|---|
| 283 | tiscali.co.uk. 3600 IN SOA ns0.tiscali.co.uk. hostmaster.talktalkplc.com. |
|---|
| 284 | 2011012703 10800 3600 604800 3600 |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | AA is set, but there is nothing in the answer apart from the SOA. The |
|---|
| 288 | parameters in the SOA are used to work out how much negative caching is |
|---|
| 289 | allowed. |
|---|
| 290 | |
|---|
| 291 | Meaning of flags (from RFC 1034/RFC 1035) |
|---|
| 292 | ----------------------------------------- |
|---|
| 293 | |
|---|
| 294 | QR A one bit field that specifies whether this message is a |
|---|
| 295 | query (0), or a response (1). |
|---|
| 296 | |
|---|
| 297 | AA Authoritative Answer - this bit is valid in responses, |
|---|
| 298 | and specifies that the responding name server is an |
|---|
| 299 | authority for the domain name in question section. |
|---|
| 300 | |
|---|
| 301 | RD Recursion Desired - this bit may be set in a query and |
|---|
| 302 | is copied into the response. If RD is set, it directs |
|---|
| 303 | the name server to pursue the query recursively. |
|---|
| 304 | Recursive query support is optional. |
|---|
| 305 | |
|---|
| 306 | RA Recursion Available - this be is set or cleared in a |
|---|
| 307 | response, and denotes whether recursive query support is |
|---|
| 308 | available in the name server. |
|---|
| 309 | |
|---|
| 310 | As well as the lack of 'AA' flag, a good way to spot cached answers |
|---|
| 311 | is to repeat the query a few times and watch the TTL counting downwards. |
|---|
| 312 | |
|---|
| 313 | $ dig psg.com. |
|---|
| 314 | ;; ANSWER SECTION: |
|---|
| 315 | psg.com. 14397 IN A 147.28.0.62 |
|---|
| 316 | ^^^^^ |
|---|
| 317 | $ dig psg.com. |
|---|
| 318 | ;; ANSWER SECTION: |
|---|
| 319 | psg.com. 14384 IN A 147.28.0.62 |
|---|
| 320 | ^^^^^ |
|---|