Domain IP Lookup

ほぼすべてのゾーンで出会うレコード

Aホスト名をIPv4アドレスに対応付け
AAAAホスト名をIPv6アドレスに対応付け
CNAMEホスト名を別のホスト名に対応付け
MXドメインをメールサーバーに優先度順で対応付け
TXTドメインを任意のテキストに対応付け。SPF、DKIM、所有確認など
NSドメインを応答するネームサーバーに対応付け
DNSの基礎

Inside a DNS Message: Header Flags, Sections and Wire Format

読了時間:5分

Every DNS lookup, from a browser asking for an address to a resolver chasing a delegation, is a short binary message in one common format. You rarely see the bytes, but tools such as dig print the header fields as text, and knowing what they mean turns that output from noise into evidence. The format has been specified by RFC 1035 since 1987, refining RFC 883 of 1983, and has been extended since, not replaced.

The 12-byte header

Every message begins with the same 12 bytes: a 16-bit ID, a 16-bit word of flags and codes, and four 16-bit counts.

FieldSizeMeaning
ID16 bitsChosen by the client and copied into the reply, so the client can match answers to questions
QR1 bit0 for a query, 1 for a response
Opcode4 bitsThe kind of request; 0 is a standard query
AA1 bitAuthoritative answer: the responding server is an authority for the name in the question
TC1 bitTruncated: the message was longer than the transport allows
RD1 bitRecursion desired: the client asks the server to do the whole lookup
RA1 bitRecursion available: the server offers that service
Z3 bitsReserved in RFC 1035; DNSSEC later took two of these bits for AD and CD (RFC 2535, restated in RFC 4035)
RCODE4 bitsResponse code: the outcome of the query
QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT16 bits eachHow many entries the question, answer, authority and additional sections hold

After the header come the four sections, in that order. The question section echoes what was asked, the answer section holds the records that answer it, the authority section points to the nameservers responsible for the zone, and the additional section carries extra records the server expects the client to want next, such as the addresses of those nameservers.

Take AA with care. A recursive resolver answering from its cache is not an authority for that data and does not set it. In the original design, a server marks an answer authoritative when it answers from zone data it holds, as opposed to cached data (Mockapetris and Dunlap, 1988). Seeing aa in a reply from one of a zone's own nameservers is the normal case, except for a referral to a child zone, which does not carry it even from an authoritative server.

Reading dig's header line

dig prints the header on two lines. A typical response looks like this:

The header as dig prints it
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6891
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

opcode and status are the Opcode and RCODE fields. The flags line lists the bits that are set, here qr, rd and ra, which together mean: a response, to a query that asked for recursion, from a server that offers it. The four counts are the section sizes. The ADDITIONAL: 1 is usually the server's EDNS pseudo-record, returned because dig includes one in its query; it is not an extra address.

The status is the quickest thing to read. RFC 1035 defines six response codes.

CodeNameMeaning
0NOERRORThe query was processed without error
1FORMERRThe server could not interpret the query
2SERVFAILThe server failed while processing the query
3NXDOMAINThe name does not exist; RFC 1035 calls this a Name Error and defines it for authoritative servers
4NOTIMPThe server does not support that kind of query
5REFUSEDThe server declines to answer for policy reasons

One common result has no code of its own. A name that exists but has no record of the type you asked for returns NOERROR with no records of that type in the answer section (a CNAME may still appear), which RFC 2308 names NODATA. The difference matters when you are diagnosing; see NXDOMAIN explained and DNS timeout vs SERVFAIL for what to do with each.

A query, byte by byte

This is a complete query for the A record of example.com in its classic form, without EDNS, as a client would send it with recursion requested. It is 29 bytes long.

A DNS query for example.com, type A, in hexadecimal
1a 2b 01 00 00 01 00 00 00 00 00 00 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 00 01 00 01
BytesMeaning
1a 2bID: an arbitrary value chosen by the client
01 00Flags: only RD is set
00 01QDCOUNT: one question
00 00 00 00 00 00ANCOUNT, NSCOUNT and ARCOUNT: all zero in a query
07 65 78 61 6d 70 6c 65A label of length 7, then the ASCII letters of “example”
03 63 6f 6dA label of length 3, then “com”
00The zero-length root label, which ends the name
00 01QTYPE 1: the A record
00 01QCLASS 1: the Internet class

The same bytes travel inside encrypted transports. In DNS over HTTPS (RFC 8484), for instance, the same message travels either as the raw body of an HTTP POST or, in a GET request, base64url-encoded into a dns parameter, and clients are advised to set the ID to 0; see DNS over HTTPS and DNS over TLS explained.

Names, limits and compression

A name is a sequence of labels, each preceded by its length, ending in a zero byte. RFC 1035 limits a label to 63 octets and a whole name to 255. Because a label's length byte never exceeds 63, its top two bits are always zero, and that left room for compression: when the top two bits are both one, that byte and the next form a pointer, and the remaining 14 bits give an offset from the start of the message. In a response, the answer's name is very commonly the two bytes c0 0c, a pointer to offset 12, where the question's name begins right after the header. Every DNS program must understand pointers in the messages it receives, though it may choose not to produce them.

Why 512 bytes mattered, and what replaced it

RFC 1035 restricts UDP messages to 512 bytes, not counting the IP and UDP headers. A longer message is truncated and the TC bit is set, which tells the client to retry over TCP. The original designers judged the datagram limit a success rather than a problem: performance was much better than over TCP circuits and operating-system resources were not tied up, although the choice demanded careful retransmission strategies (Mockapetris and Dunlap, 1988).

As responses grew with IPv6 and DNSSEC, the limit became tight. EDNS(0), defined in RFC 6891, lets a client advertise a larger UDP payload size in an OPT pseudo-record. The RFC suggests 4096 octets as a starting point and a fallback to a range around 1280 to 1410 bytes if that fails. Since RFC 7766 in 2016, support for TCP has been a required part of a complete DNS implementation. Larger UDP responses also have a security cost, because they make reflection attacks more profitable; DNS amplification attacks and open resolvers covers that.

重要なポイント

Read the header first: QR says query or response, RCODE says what happened, AA says whether the answer came from an authority, and TC says to retry over TCP.

Sources and further reading

ドメインの公開DNSアドレスを調べたい場合は、Domain IP Lookupツールをお試しください。

dns message formatdns header flagsdig outputdns response codes

よくある質問

関連記事

再帰的なDNS検索を1ホップずつ見る

ブラウザー

example.comを要求

リゾルバー

ISP / 1.1.1.1

ルート + TLD

.comの管理元は?

権威サーバー

正式な回答

この連鎖の各ホップはそれ自体がDNS検索で、結果はその後キャッシュされます

DNSの基礎

DNSの仕組み:ドメイン名からIPアドレスまで

インターネットの電話帳を、端から端まで追跡します。ドメインを入力してから最初のパケットがサーバーに届くまでの数ミリ秒に、何が起きているのかを解説します。

読了時間:3分

4つの結果と、それぞれ異なる次の対応

NXDOMAIN名前が存在しない。再試行は無意味
TIMEOUT時間内に応答なし。一時的なことが多い
SERVFAILサーバーが処理できなかった。一時的な場合もある
REFUSEDポリシーにより拒否。障害や一時的な問題であることは稀
トラブルシューティング

DNSタイムアウトとSERVFAILの違い

どちらも名前解決の失敗に見えますが、タイムアウトとSERVFAILは原因が異なり、次に取るべき対応も変わります。両者の違いと見分け方を解説します。

読了時間:3分

ほぼすべてのゾーンで出会うレコード

Aホスト名をIPv4アドレスに対応付け
AAAAホスト名をIPv6アドレスに対応付け
CNAMEホスト名を別のホスト名に対応付け
MXドメインをメールサーバーに優先度順で対応付け
TXTドメインを任意のテキストに対応付け。SPF、DKIM、所有確認など
NSドメインを応答するネームサーバーに対応付け
DNSの基礎

DNSレコードタイプ徹底解説:完全リファレンス

知っておくべきレコードタイプのすべてについて、役割、書式、そして陥りがちな間違いを、1つのリファレンスページにまとめました。

読了時間:4分