§2.4.3DNS Records and Messages

Application layer Kurose & Ross pp. 131–135 · ~17 min read

  • resource record
  • dns time to live
  • type a record
  • type ns record
  • type cname record
  • type mx record
  • registrar
  • dns poisoning

Where you are

  • Application layer you are here
  • Transport layer
  • Network layer
  • Link layer
  • Physical layer

Everything DNS (Domain Name System) holds is a four-field record and everything it says uses one message format. Getting a new name into the system means writing four records in two places.

Words you will meet

  • Resource record — one entry in the DNS database, written as four fields.
  • TTL — Time To Live: how long a cached record may be kept.
  • Type A record — gives the IP (Internet Protocol) address of a named host.
  • Type NS (Name Server) record — names the server that knows the answers for a domain.
  • Type CNAME record — says “this nickname really means that official name”.
  • Type MX (Mail eXchange) record — names the mail server for a domain.
  • Registrar — a company that sells domain names and puts them into DNS for you.
  • DNS poisoning — feeding a DNS server false records so it sends people astray.

Why this matters

Section 2.4.2 showed the shape of the system. This section shows what is actually stored and actually sent, which is the difference between knowing how DNS works and being able to read a packet capture of it.

It also closes the loop. Everything so far has been about reading DNS. The last part of this section is the only place in the chapter that explains how anything gets written into it.

Resource records

The DNS servers that together implement the distributed database store resource records ( RR (Resource Record) s), including records that provide hostname-to-IP-address mappings. Each DNS reply message carries one or more of them.

A resource record is a four-tuple:

(Name, Value, Type, TTL)

TTL (Time To Live) is the time to live of the record: it determines when the record should be removed from a cache. In the examples below it is ignored, as the book ignores it.

Name and Value have no fixed meaning

The meaning of Name and Value depends on Type. That is not a quirk; it is the design. Four record types share two slots, and what those slots hold changes completely from one type to the next.

So the four types have to be learned together. Reading the table below one row at a time will not work.

The four record types, and what Name and Value mean in each
Name is…Value is…Example
An NS record names a server by hostname, and you cannot send a packet to a hostname. So it almost always travels with a Type A record giving that server’s address — otherwise resolving the referral would need its own lookup, which would need its own, and so on.

Cells marked ⓘ have an explanation — click to read it. Sortable columns have a ↕ in the heading.

Sort by Type, or read down the examples. The two middle columns change meaning from row to row — that is the whole idea.

Which records a server actually holds

There is a simple rule, and it explains the shape of every query chain in section 2.4.2.

  • If a DNS server is authoritative for a hostname, it holds a Type A record for that hostname. (Even a server that is not authoritative may hold one in its cache.)
  • If a server is not authoritative, it holds a Type NS (Name Server) record for the domain containing the hostname — and also a Type A record giving the IP address of the server named in that NS record.

Worked example — what an edu TLD (Top-Level Domain) server holds

Suppose an edu TLD (Top-Level Domain) server is not authoritative for gaia.cs.umass.edu. Then it contains a record for a domain that includes that host:

(umass.edu, dns.umass.edu, NS)

and it also contains a Type A record mapping that server to an address:

(dns.umass.edu, 128.119.40.111, A)

Why both? The NS record names a server by hostname, and you cannot send a packet to a hostname. Without the A record beside it, resolving the referral would need its own lookup — which would need its own, and so on. The pair stops the regress.

The other two types implement the aliasing services of section 2.4.1. A Type CNAME (Canonical Name) record gives the canonical hostname behind an alias. A Type MX (Mail eXchange) record gives the canonical name of a mail server that has an alias.

DNS messages

There are only two kinds of DNS message — query and reply — and both have the same format.

Figure 2.21 — the DNS message format
08162432bitIdentification16 bitsFlags16 bitsNumber of questions16 bitsNumber of answer RRs16 bitsNumber of authority RRs16 bitsNumber of additional RRs16 bitsQuestionsName and type fields for a queryAnswersvariable number of resource recordsRRs in response to the queryAuthorityvariable number of resource recordsRecords for authoritative serversAdditional informationvariable number of resource recordsAdditional “helpful” info

Click any box to read what that part of the message is for.

Every field, as text
  • Identification — 16 bits — A 16-bit number that identifies this query. (example: 0x1a2b)
  • Flags — 16 bits — Several one-bit flags. See the expansion below. (example: QR=0, RD=1)
  • Number of questions — 16 bits — How many entries the questions section holds. (example: 1)
  • Number of answer RRs — 16 bits — How many resource records the answer section holds. (example: 1)
  • Number of authority RRs — 16 bits — How many records the authority section holds. (example: 0)
  • Number of additional RRs — 16 bits — How many records the additional section holds. (example: 1)

Query and reply are the only two kinds of DNS message, and both use this format. Click any field.

In plain words — what the four counts are for

There is no length field anywhere in a DNS message. Instead the header carries four number-of fields, one per section, and those counts tell the receiver how many entries to expect in each.

It is a small design decision with a large consequence: a receiver can parse the message without knowing its total size in advance.

Inside the 16-bit flags field
0816bitQRother4 bitsAAxRDRAother flag bits7 bits

Click any box to read what that part of the message is for.

Every field, as text
  • QR — 1 bits — Query or reply. (example: 0)
  • other — 4 bits — Further flag bits the book does not detail.
  • AA — 1 bits — Authoritative answer. (example: 1)
  • x — 1 bits — A further flag bit the book does not detail.
  • RD — 1 bits — Recursion desired. (example: 1)
  • RA — 1 bits — Recursion available. (example: 0)
  • other flag bits — 7 bits — The remainder of the field, which the book does not detail.

The book names four of these flags in prose without giving their positions. The positions drawn here are from RFC 1035; the four the book names are labelled, and the rest are marked as such rather than invented.

One real query and its reply
message 2 of 2
Lin’s laptopTimeLocal DNS server41.72.0.53Timequery — id 0x1a2b, QR=0, RD=1reply — id 0x1a2b, QR=1, one answer

Click any arrow to see what that message says and why it is sent.

The same two messages the §2.4.1 ladder showed, now with their fields filled in. Click either arrow.

Read this diagram as text
  1. Lin’s laptop sends query — id 0x1a2b, QR=0, RD=1 to Local DNS server. One question, no answers. Recursion desired is set, because a host does want its local server to do the walking.
  2. Local DNS server sends reply — id 0x1a2b, QR=1, one answer to Lin’s laptop. The identification is copied back unchanged: that is how the laptop knows this reply belongs to that query. The question is echoed, and the answer section carries the record.

Lifelines, left to right: Lin’s laptop (host), Local DNS server (server).

Try it yourself

You can send a DNS query straight from your own machine with the nslookup program, available on most Windows and UNIX platforms. Type nslookup at a command prompt, then send a query to any DNS server — root, TLD or authoritative. nslookup displays the records in the reply in a human-readable format.

If you would rather not run it locally, many websites let you use nslookup remotely.

Where this breaks: nslookup shows you the records, not the bytes. The identification field, the flag bits and the four counts — everything the diagrams above are about — are parsed away before you see anything. The Wireshark lab at the end of this chapter is where you meet the actual message.

Getting records into the database

Everything so far has been about retrieving records. How do they get in?

The first step is to register the domain name with a registrar . A registrar is a commercial entity that verifies the name is unique, enters it into the DNS database, and collects a small fee. ICANN (Internet Corporation for Assigned Names and Numbers) accredits them.

Getting records into the database: registering networkutopia.com
1 — Register the name with a registrarstep 1 of 5
You have started a company called Network UtopiaYouA registrar“I want networkutopia.com”

A registrar is a commercial entity that verifies the domain name is unique, enters it into the DNS database, and collects a small fee. Before 1999 a single registrar, Network Solutions, held a monopoly on com, net and org. Today many compete, and ICANN accredits them.

Everything so far has been about reading DNS. This is how anything gets written into it.

Read all steps as text
  1. 1 — Register the name with a registrarA registrar is a commercial entity that verifies the domain name is unique, enters it into the DNS database, and collects a small fee. Before 1999 a single registrar, Network Solutions, held a monopoly on com, net and org. Today many compete, and ICANN accredits them.
  2. 2 — Give it your authoritative serversYou supply the names and IP addresses of your primary and secondary authoritative DNS servers: dns1.networkutopia.com and dns2.networkutopia.com, at 212.212.212.1 and 212.212.212.2.
  3. 3 — The registrar writes two records into the com TLD serversFor each of your two authoritative servers it inserts an NS record and an A record. The NS record says who is authoritative; the A record gives that server an address, so a querying server can act on the referral without a further lookup.
  4. 4 — You write your own records into your own serversInto your authoritative servers you put a Type A record for your web server www.networkutopia.com, and a Type MX record for your mail server mail.networkutopia.com. Until recently these were configured statically from a file written by a system manager; an UPDATE option now allows data to be added and deleted dynamically through DNS messages.
  5. 5 — Alice in Australia visits your siteHer host queries her local DNS server, which contacts a com TLD server. That server holds the two records the registrar inserted, so it replies with both. Her local server then queries 212.212.212.1 for the Type A record of www.networkutopia.com, gets 212.212.71.4, and passes it back. Her browser opens a TCP connection and sends an HTTP request.

A typo in the book

The book gives your two authoritative servers’ addresses on book page 134 as 212.2.212.1 and 212.212.212.2, then uses 212.212.212.1 on page 136 when it writes out the record.

212.212.212.1 is the consistent one, and this site uses it throughout. Flagged because a reader comparing the two pages would otherwise think they had misunderstood something.

Once all this is done, people can visit your website and send e-mail to your staff. That claim is worth verifying rather than accepting, which is what step 5 above does.

Until recently the contents of each DNS server were configured statically, from a configuration file written by a system manager. An UPDATE option has since been added to the DNS protocol, allowing data to be added to or deleted from the database dynamically through DNS messages.

Focus on security: attacking DNS

DNS is a critical component of the Internet infrastructure, and many important services — the Web and e-mail among them — simply cannot function without it. So it is fair to ask how it can be attacked. Is it a sitting duck?

Flooding the roots, 21 October 2002

The obvious attack is a DDoS (Distributed Denial of Service) bandwidth-flooding attack against the DNS servers, and one was attempted. Attackers used a botnet to send enormous numbers of ICMP (Internet Control Message Protocol) ping messages to each of the 13 root IP addresses.

It caused minimal damage. Two things saved the roots:

  1. Many of them were protected by packet filters configured to block all ICMP ping messages directed at them. Those servers were spared and worked normally.
  2. Most local DNS servers cache the addresses of TLD servers, so the query process often bypasses the roots anyway — exactly as section 2.4.2 explained.

Flooding a TLD provider, 21 October 2016

A potentially more effective attack sends a deluge of DNS queries to top-level-domain servers instead. This is harder to defend, for two reasons that mirror the two defences above. DNS queries are harder to filter than ICMP pings, and TLD servers are not so easily bypassed by caching.

Such an attack took place against the TLD service provider Dyn, exactly fourteen years to the day after the attack on the roots. It used a botnet of about one hundred thousand IoT (Internet of Things) devices — printers, IP cameras, residential gateways, baby monitors — infected with Mirai malware.

For almost a full day, Amazon, Twitter, Netflix, Github and Spotify were disturbed.

In plain words

Nobody attacked Amazon, Twitter, Netflix, Github or Spotify. Their servers were fine the whole time.

What failed was the ability to turn their names into addresses, and that was enough. This is what section 2.4.1 meant by calling DNS a core network function.

Forging replies

DNS can be attacked in other ways. In a man-in-the-middle attack the attacker intercepts queries from hosts and returns bogus replies. In the DNS poisoning attack the attacker sends bogus replies to a DNS server, tricking it into accepting bogus records into its cache.

Either could redirect an unsuspecting user to the attacker’s website.

The DNS Security Extensions ( DNSSEC (DNS Security Extensions) ) have been designed and deployed to protect against such exploits. DNSSEC is a secured version of DNS that addresses many of these attacks, and it is gaining popularity.

DNSSEC does not stop a flood

Notice that the two families of attack need different defences. DNSSEC protects against forged replies — man-in-the-middle and poisoning — by letting a resolver check that a record really came from the right server.

It does nothing whatever against a flood. Signing a reply does not help if the reply never gets sent.

Check yourself

Check yourself

0 of 7 answered
  1. 1.A resource record is a four-tuple (Name, Value, Type, TTL). Why can you not say what Name and Value mean without looking at Type?

  2. 2.An edu TLD server is not authoritative for gaia.cs.umass.edu. Which records does it hold, and why two rather than one?

  3. 3.predictLook at the DNS message diagram. The header is 12 bytes. How is that made up?

  4. 4.What is the identification field for?

  5. 5.A client asks for the MX record of a domain. The answer section names a mail server. What is likely in the additional section, and why is that useful?

  6. 6.You register networkutopia.com. Which records does the registrar insert into the com TLD servers?

  7. 7.The 2002 attack on the root servers did little damage; the 2016 attack on Dyn disturbed Amazon, Twitter, Netflix, Github and Spotify for almost a full day. What made the difference?

What to remember

  • A resource record is (Name, Value, Type, TTL). What Name and Value mean depends on Type, so the four types must be learned together.
  • A = hostname → address. NS = domain → authoritative server’s hostname. CNAME = alias → canonical name. MX = alias → mail server’s canonical name.
  • The 2002 flood of the roots failed, because of packet filters and caching. The 2016 flood of Dyn worked: DNS queries are harder to filter, and TLD servers are not bypassed by caching. DNSSEC defends against forged replies and does nothing against a flood.