← Back to Learning Hub

Security • Intermediate • 6 min read

DNS Cookies (RFC 7873): Lightweight Protection Against Spoofing

How DNS Cookies add a cheap client-server token to UDP queries to blunt off-path spoofing and amplification abuse, and how they differ from full DNSSEC signing.

Plain DNS over UDP has an old, structural weakness: a server cannot easily tell whether the query it just received really came from the address in the packet. That gap is what off-path attackers exploit to spoof answers and what lets abusers bounce huge amplified responses off open resolvers toward a victim. DNS Cookies are a lightweight fix for both. They add a small token that a client and server exchange, cheap to compute and carried in every query, that proves a query really came from the address it claims. This guide explains how DNS Cookies work, how the client and server halves fit together, the two attacks they blunt, and how they differ from the much heavier protection DNSSEC provides.

The problem: UDP has no return address proof

A UDP packet's source address is trivially forged. Two problems follow. First, an off-path attacker who cannot see your real queries can still flood a resolver with guessed answers, hoping one matches an outstanding query's port and transaction ID before the real answer arrives; success poisons the cache. Second, an attacker can send a small query to an open server with the victim's address as the forged source, and the server dutifully sends a much larger answer to the victim. That second pattern is the engine of reflection and amplification abuse, covered in our guide on DNS amplification attacks and response rate limiting.

How DNS Cookies work

DNS Cookies are defined in RFC 7873, published in May 2016. A cookie is an EDNS0 option, option code 10, carried in the OPT record of queries and responses, so it rides along inside normal DNS messages with no new protocol or port. The exchange has two halves.

PartSizeCreated byPurpose
Client Cookie8 bytesThe client (resolver)A value the client sends and expects echoed, tying a response to its query
Server Cookie8 to 32 bytesThe serverA keyed value proving the client previously reached this server from its real address

On the first query to a server the client sends only its Client Cookie. The server replies with that Client Cookie plus a freshly computed Server Cookie, which is essentially a keyed hash tied to the client's IP address. From then on the client includes both cookies in its queries. The server recomputes the Server Cookie and checks it: a valid one proves the query came from an address that genuinely received a cookie before, which an off-path spoofer cannot have obtained.

The two attacks it blunts

Against cache poisoning, the Client Cookie adds a value the attacker cannot see and must therefore guess alongside the port and transaction ID, sharply raising the work needed to forge an accepted answer. Against reflection and amplification, the Server Cookie lets a server recognize a request that lacks a valid cookie and respond minimally, typically with a tiny error rather than a large answer, so a spoofed query no longer yields a big packet aimed at a victim. When a server receives a query with a Client Cookie but no valid Server Cookie, it can answer with the extended error code BADCOOKIE and a fresh Server Cookie, prompting a legitimate client to retry with the correct token while giving a spoofer nothing worth reflecting.

Interoperability and the updated server cookie

The original specification left the exact Server Cookie construction loosely defined, which caused problems for anycast deployments where many physical servers share one address and must all accept each other's cookies. RFC 9018, published in April 2021, standardizes the Server Cookie format and algorithm, based on SipHash, so that a cookie minted by one node in an anycast cluster validates on every other node. As of November 2026 DNS Cookies are widely implemented in common resolver and authoritative software and are often enabled by default, though they remain optional and are negotiated per server, so a mixed internet still has servers that do not use them.

Checking and enabling DNS Cookies

You can observe the cookie exchange from the client side and confirm your own servers participate.

  1. Query with cookies explicitly using dig +cookie example.com @your-server and look in the output for a COOKIE line in the OPT pseudosection.
  2. On a first contact you will see your Client Cookie echoed together with a longer Server Cookie the server has added.
  3. Repeat the query; dig reuses the Server Cookie, and a healthy exchange shows it accepted without a BADCOOKIE retry.
  4. If you run the server, enable DNS Cookies in its configuration and, for anycast, ensure every node shares the same secret so cookies validate cluster-wide per RFC 9018.
  5. Pair cookies with response rate limiting; cookies cut spoofed amplification, and rate limiting handles the residual load from clients that never present a valid cookie.

What cookies do not do

DNS Cookies are a transaction-level defense, not data authentication. They make it hard to spoof where a query or response came from, but they do not prove that the records inside an answer are genuine and unmodified by the authoritative operator or an on-path attacker. For that you need cryptographic signatures over the data itself.

Frequently asked questions

Are DNS Cookies a replacement for DNSSEC?

No. DNS Cookies protect the transaction, proving a query or response came from the claimed address, while DNSSEC signs the records so a resolver can prove the data is authentic. They solve different problems and are complementary, not alternatives.

Do DNS Cookies require a new port or protocol?

No. A cookie is an EDNS0 option carried in the OPT record of ordinary DNS messages over the usual port. Both ends simply need EDNS0 and cookie support, which modern software has, so nothing about ports or firewalls changes.

What is a BADCOOKIE response?

BADCOOKIE is an extended error a server returns when a query carries a Client Cookie but no valid Server Cookie. It includes a fresh Server Cookie so a legitimate client retries with the right token, while a spoofing source gains nothing useful from the small reply.

Will cookies stop all DNS spoofing?

They stop off-path spoofing, where the attacker cannot see your traffic, by adding a value the attacker must guess. They do not defend against an on-path attacker who can read the real cookies, so they raise the bar rather than closing every path.

Do I need to enable cookies on both client and server?

Both ends must support cookies for the exchange to help, and they negotiate per server. As of November 2026 many resolvers and authoritative servers enable them by default, but a server that ignores cookies simply gets no protection from them for that exchange.

DNS Cookies are a small, cheap addition that meaningfully raises the cost of off-path spoofing and shuts down reflection abuse, without the operational weight of signing a zone. To inspect the records and responses a name returns while you verify your setup, use the Valla DNS lookup tool, and see our guide on EDNS0 for the extension mechanism that carries cookies in the first place.

Troubleshooting box

If results look inconsistent, compare authoritative nameservers first, then recursive resolvers by region. Capture snapshots every 10 minutes for deterministic incident timelines.

Try VallaDNS free →

Intermediate • 6 min

How to Find a DNS Record's TTL (Current Value)

Find the TTL currently set on a DNS record: read the TTL column in dig and nslookup, tell the authoritative TTL from a resolver's countdown, and confirm a change.

Intermediate • 7 min

How to Check If Nameservers Have Propagated

Nameserver changes live at the parent TLD and follow the registry NS TTL, not your zone. Check the parent delegation and confirm the new NS set worldwide.