← Lessons

quiz vs the machine

Platinum1780

Networking

Anycast for DNS

How one IP address routes to the nearest of many DNS servers.

5 min read · advanced · beat Platinum to climb

One address, many servers

In anycast, the same IP address is announced from many locations at once. The internet routing system delivers each packet to whichever instance is closest by routing metrics, so users near each site reach a nearby server automatically.

Why DNS loves it

DNS is a near perfect fit for anycast because most queries are short and stateless, a single request and reply over UDP:

  • Many physical servers share one advertised address, so resolvers need only one to configure.
  • Routing steers each query to the nearest healthy instance, lowering latency.
  • If one site fails, its route is withdrawn and traffic shifts to the next nearest site.

This gives both performance and resilience without the client knowing anything changed. The root and major public resolvers run on anycast for exactly these reasons.

The stateful caveat

Anycast works cleanly when each request stands alone. For long lived stateful sessions, a routing change mid connection could send packets to a different instance that has no state. Because DNS queries are tiny and independent, this caveat rarely bites it.

Key idea

Anycast advertises one DNS address from many sites, letting routing send each stateless query to the nearest healthy server while withdrawing failed sites automatically.

Check yourself

Answer to earn rating on the learn ladder.

1. How does anycast route a query?

2. Why is DNS well suited to anycast?

3. What happens when an anycast site fails?