Skip to main content

Header, Question and Resource Record Formats

Header section format​

     +-----------------------------------------------+
| |
| ***** WARNING ***** |
| |
| The following format is preliminary and is |
| included for purposes of explanation only. In |
| particular, the size and position of the |
| OPCODE, RCODE fields and the number and |
| meaning of the single bit fields are subject |
| to change. |
| |
+-----------------------------------------------+

The header contains the following fields:

                                     1  1  1  1  1  1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ID |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR| Opcode |AA|TC|RD|RA| | RCODE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QDCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ANCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| NSCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ARCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

where:

ID      - A 16 bit identifier assigned by the program that
          generates any kind of query.  This identifier is copied
          into all replies and can be used by the requestor to
          relate replies to outstanding questions.

QR      - A one bit field that specifies whether this message is a
          query (0), or a response (1).

OPCODE  - A four bit field that specifies kind of query in this
          message.  This value is set by the originator of a query
          and copied into the response.  The values are:

                  0   a standard query (QUERY)

                  1   an inverse query (IQUERY)

                  2   an completion query allowing multiple
                      answers (CQUERYM)

                  2   an completion query requesting a single
                      answer (CQUERYU)

                  4-15 reserved for future use

AA      - Authoritative Answer - this bit is valid in responses,
                   and specifies that the responding name server
                   is an authority for the domain name in the
                   corresponding query.

TC      - TrunCation - specifies that this message was truncated
                   due to length greater than 512 characters.
                   This bit is valid in datagram messages but not
                   in messages sent over virtual circuits.

RD      - 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.

RA      - Recursion Available - this be is set or cleared in a
                   response, and denotes whether recursive query
                   support is available in the name server.

RCODE   - Response code - this 4 bit field is set as part of
                   responses.  The values have the following
                   interpretation:

                  0    No error condition

                  1    Format error - The name server was unable
                       to interpret the query.

                  2    Server failure - The name server was unable
                       to process this query due to a problem with
                       the name server.

                  3    Name Error - Meaningful only for responses
                       from an authoritative name server, this
                       code signifies that the domain name
                       referenced in the query does not exist.

                  4    Not Implemented - The name server does not
                       support the requested kind of query.

                  5    Refused - The name server refuses to
                       perform the specified operation for policy
                       reasons.  For example, a name server may
                       not wish to provide the information to the
                       particular requestor, or a name server may
                       not wish to perform a particular operation
                       (e.g. zone transfer) for particular data.

                  6-15 Reserved for future use.

QDCOUNT - an unsigned 16 bit integer specifying the number of
          entries in the question section.

ANCOUNT - an unsigned 16 bit integer specifying the number of
          resource records in the answer section.

NSCOUNT - an unsigned 16 bit integer specifying the number of name
          server resource records in the authority records
          section.

ARCOUNT - an unsigned 16 bit integer specifying the number of
          resource records in the additional records section.

Question section format​

The question section is used in all kinds of queries other than inverse queries. In responses to inverse queries, this section may contain multiple entries; for all other responses it contains a single entry. Each entry has the following format:

                                     1  1  1  1  1  1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| |
/ QNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QTYPE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QCLASS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

where:

QNAME -   a variable number of octets that specify a domain name.
This field uses the compressed domain name format
described in the next section of this memo. This field
can be used to derive a text string for the domain name.
Note that this field may be an odd number of octets; no
padding is used.

QTYPE - a two octet code which specifies the type of the query.
The values for this field include all codes valid for a
TYPE field, together with some more general codes which
can match more than one type of RR. For example, QTYPE
might be A and only match type A RRs, or might be MAILA,
which matches MF and MD type RRs. The values for this
field are listed in Appendix 2.

QCLASS - a two octet code that specifies the class of the query.
For example, the QCLASS field is IN for the ARPA
Internet, CS for the CSNET, etc. The numerical values
are defined in Appendix 2.

Resource record format​

The answer, authority, and additional sections all share the same format: a variable number of resource records, where the number of records is specified in the corresponding count field in the header. Each resource record has the following format:

                                     1  1  1  1  1  1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| |
/ /
/ NAME /
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| TYPE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| CLASS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| TTL |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| RDLENGTH |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
/ RDATA /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

where:

NAME    - a compressed domain name to which this resource record
pertains.

TYPE - two octets containing one of the RR type codes defined
in Appendix 2. This field specifies the meaning of the
data in the RDATA field.

CLASS - two octets which specify the class of the data in the
RDATA field.

TTL - a 16 bit unsigned integer that specifies the time
interval (in seconds) that the resource record may be
cached before it should be discarded. Zero values are
interpreted to mean that the RR can only be used for the
transaction in progress, and should not be cached. For
example, SOA records are always distributed with a zero
TTL to prohibit caching. Zero values can also be used
for extremely volatile data.

RDLENGTH- an unsigned 16 bit integer that specifies the length in
octets of the RDATA field.

RDATA - a variable length string of octets that describes the
resource. The format of this information varies
according to the TYPE and CLASS of the resource record.
For example, the if the TYPE is A and the CLASS is IN,
the RDATA field is a 4 octet ARPA Internet address.

Formats for particular resource records are shown in Appendicies 2 and 3.

Domain name representation and compression​

Domain names messages are expressed in terms of a sequence of labels. Each label is represented as a one octet length field followed by that number of octets. Since every domain name ends with the null label of the root, a compressed domain name is terminated by a length byte of zero. The high order two bits of the length field must be zero, and the remaining six bits of the length field limit the label to 63 octets or less.

To simplify implementations, the total length of label octets and label length octets that make up a domain name is restricted to 255 octets or less. Since the trailing root label and its dot are not printed, printed domain names are 254 octets or less.

Although labels can contain any 8 bit values in octets that make up a label, it is strongly recommended that labels follow the syntax described in Appendix 1 of this memo, which is compatible with existing host naming conventions. Name servers and resolvers must compare labels in a case-insensitive manner, i.e. A=a, and hence all character strings must be ASCII with zero parity. Non-alphabetic codes must match exactly.

Whenever possible, name servers and resolvers must preserve all 8 bits of domain names they process. When a name server is given data for the same name under two different case usages, this preservation is not always possible. For example, if a name server is given data for ISI.ARPA and isi.arpa, it should create a single node, not two, and hence will preserve a single casing of the label. Systems with case sensitivity should take special precautions to insure that the domain data for the system is created with consistent case.

In order to reduce the amount of space used by repetitive domain names, the sequence of octets that defines a domain name may be terminated by a pointer to the length octet of a previously specified label string. The label string that the pointer specifies is appended to the already specified label string. Exact duplication of a previous label string can be done with a single pointer. Multiple levels are allowed.

Pointers can only be used in positions in the message where the format is not class specific. If this were not the case, a name server that was handling a RR for another class could make erroneous copies of RRs. As yet, there are no such cases, but they may occur in future RDATA formats.

If a domain name is contained in a part of the message subject to a length field (such as the RDATA section of an RR), and compression is used, the length of the compressed name is used in the length calculation, rather than the length of the expanded name.

Pointers are represented as a two octet field in which the high order 2 bits are ones, and the low order 14 bits specify an offset from the start of the message. The 01 and 10 values of the high order bits are reserved for future use and should not be used.

Programs are free to avoid using pointers in datagrams they generate, although this will reduce datagram capacity. However all programs are required to understand arriving messages that contain pointers.

For example, a datagram might need to use the domain names F.ISI.ARPA, FOO.F.ISI.ARPA, ARPA, and the root. Ignoring the other fields of the message, these domain names might be represented as:

       +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
20 | 1 | F |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
22 | 3 | I |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
24 | S | I |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
26 | 4 | A |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
28 | R | P |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
30 | A | 0 |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
40 | 3 | F |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
42 | O | O |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
44 | 1 1| 20 |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
64 | 1 1| 26 |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
92 | 0 | |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

The domain name for F.ISI.ARPA is shown at offset 20. The domain name FOO.F.ISI.ARPA is shown at offset 40; this definition uses a pointer to concatenate a label for FOO to the previously defined F.ISI.ARPA. The domain name ARPA is defined at offset 64 using a pointer to the ARPA component of the name F.ISI.ARPA at 20; note that this reference relies on ARPA being the last label in the string at 20. The root domain name is defined by a single octet of zeros at 92; the root domain name has no labels.