IP Addresses & Routing

Anycast: One Address, Many Locations

Learn how one IP address can be served from many places at once, why DNS and CDNs rely on it and where the technique gets tricky.

Key takeaways

  • Anycast gives several sites one address and lets routing choose which site each packet reaches.
  • "Nearest" means best according to network routing policy, which is not always the closest on a map.
  • Withdrawing a site's route moves its users elsewhere, which provides failover.
  • Short exchanges such as DNS suit anycast naturally; long connections need more care.
  • Debugging requires finding out which site you actually reached.

Anycast means announcing the same IP address from many physical locations, so that the network's ordinary routing delivers each user to one of them, usually a nearby one. You type or configure a single address, and behind it there may be dozens of sites on several continents.

It is how many public DNS resolvers, the DNS root servers and large content delivery networks stay fast and hard to knock over. No special software is needed on your device. To it, an anycast address looks like any other.

Compared with other delivery styles

Most addresses are unicast: one address, one destination interface. Broadcast (in IPv4) sends to everything on a local network. Multicast sends to every member of a group that asked to receive. Anycast sends to just one member of a group, selected by routing.

In IPv4 there is nothing in the address itself to show that it is anycast. IPv6 also takes anycast addresses from the ordinary unicast space. The difference is entirely in how the address is announced.

Four ways to address traffic
Unicast One sender to one specific receiver. Anycast One sender to whichever group member routing picks. Multicast One sender to all members that joined a group. Broadcast One sender to every device on the local network (IPv4). Unicast One sender to one specific receiver. Anycast One sender to whichever group member routing picks. Multicast One sender to all members that joined a group. Broadcast One sender to every device on the local network (IPv4).

How routing does the choosing

Between networks, routes are exchanged with BGP. An anycast operator announces the same prefix from every site. A network that hears the prefix from several directions treats them as alternative paths to one destination and picks the best by its normal rules: business preference, then path length and further tie-breakers.

Nobody measures your latency and assigns you a site. Selection falls out of routing, router by router. The set of users who end up at a particular site is called its catchment.

Because the unit of announcement between networks is a prefix, anycast services usually dedicate a whole block, typically at least a /24 in IPv4 or a /48 in IPv6, since smaller ones are widely filtered.

Anycast also works inside one organization. An interior protocol such as OSPF can carry the same host route from several servers, and each part of the network uses the closest in routing cost.

Why DNS leans on it

A DNS query is usually a single small packet and a single reply over UDP. If routing shifts between one query and the next, nothing is lost, because each exchange stands alone. That is an ideal fit.

The root of the DNS is known by a fixed set of server names and addresses, yet those addresses are served by many hundreds of instances worldwide through anycast. See root servers for how that works. Public resolvers such as 1.1.1.1 and 8.8.8.8 are anycast too, which is why one address gives reasonable response times in many countries.

Content delivery networks use two main steering methods, often together. Some hand out different addresses through DNS based on where the question came from. Others use anycast, so one address leads to a nearby edge.

Failover and absorbing floods

Suppose a site fails. A well-built node checks the health of its own service and, when the check fails, stops announcing the route. Neighboring networks fall back to the next best path, and users land at another site. Their devices keep using the same address.

How an anycast site leaves and returns
1 Healthy The site announces the shared prefix and serves nearby users. 2 Check fails A local monitor finds the service no longer answering correctly. 3 Withdraw The site stops announcing the prefix to its neighbors. 4 Reroute Networks pick the next best site that still announces it. 5 Recover Once checks pass for a while, the announcement returns. Healthy The site announces the shared prefix and serves nearby users. 1 Check fails A local monitor finds the service no longer answering correctly. 2 Withdraw The site stops announcing the prefix to its neighbors. 3 Reroute Networks pick the next best site that still announces it. 4 Recover Once checks pass for a while, the announcement returns. 5

The important detail is that the announcement must follow the health of the service. A server that has crashed while its route is still advertised becomes a black hole for everyone in its catchment.

Anycast also helps with denial-of-service floods. Attack traffic from many sources is divided by the same routing that divides legitimate users, so each site absorbs only its share. A flood concentrated in one region may overwhelm the local site while the rest of the world notices nothing. This is part of how DDoS protection services spread load.

There is a catch. If a site collapses under load and withdraws, its flood moves to the next site, possibly toppling that one too. Operators plan capacity with this domino effect in mind, and sometimes keep an overloaded site announced to contain the damage.

The trouble with long connections

TCP keeps state at both ends. If a routing change moves your packets to a different site mid-connection, the new site knows nothing about the conversation and typically resets it.

In practice, routes between a given user and service tend to stay put long enough that web connections work well over anycast. The risk grows for long downloads, persistent connections and places where routers spread traffic across equal paths.

Operators reduce it in several ways:

  • Use anycast only to get the user in the door, then hand long transfers to a unicast address for that site.
  • Keep equal-cost load balancing consistent for each flow.
  • Share or reconstruct connection state among servers within a site.
  • Design clients to resume interrupted transfers.

QUIC identifies connections with its own connection IDs, which helps servers recognize a conversation when a user's address changes, though a different site still needs a way to find or hand off that state.

Closest is not guaranteed

Routing follows business relationships. A network might prefer a path through a paying customer to a distant site over a free-looking path to one next door. Users can be sent across an ocean while a local node sits idle.

Operators correct this by choosing where to connect, arranging peering, and adjusting announcements. Some nodes are deliberately local, announced with restrictions so only nearby networks use them. More sites don't automatically mean better latency if their routing is uneven.

Finding out which site you reached

Because every site answers with the same address, troubleshooting starts with identifying the one you hit.

Many DNS services support the NSID option, which returns a server identifier:

dig @1.1.1.1 example.com A +nsid

Some servers also answer a special query in the CHAOS class:

dig @1.1.1.1 id.server CH TXT +short

Not every operator supports either, and the format of the answer is their own. Web services behind a content delivery network often reveal the edge location in a response header; the header name varies by provider.

A traceroute shows the path, and the names of the last few routers may hint at a city. Run it from the affected network, since your own vantage point may land somewhere else entirely.

Monitoring an anycast service

One of anycast's awkward properties is that a single monitoring server sees a single site. If it sits near a healthy node, every check passes while users on another continent get errors.

Useful monitoring therefore has two sides. From inside, each node tests its own service end to end: not just that a process is running, but that a real request returns a correct, fresh answer. From outside, probes spread across many networks record which site answers them, how long it takes and whether the answer is right.

Watch catchments over time as well. A change at some distant provider can shift a large group of users to a different node overnight, raising latency or overloading a small site without anything breaking on your side. A sudden jump in traffic at one location with a matching drop at another is the usual clue.

Planned maintenance has its own routine. Withdraw the node's announcement first, wait for traffic to drain away, do the work, verify the service locally and then announce again. Taking the service down before withdrawing the route creates exactly the black hole you built anycast to avoid.

Guard against flapping too. If a health check is too sensitive, a node can announce and withdraw repeatedly, which moves users back and forth and may cause other networks to dampen or distrust the route. Require several failures before withdrawing and a longer run of successes before returning.

Should you use it?

For most website owners, anycast is something you buy. A hosted DNS provider or content delivery network supplies it, and you benefit without touching BGP.

Running your own requires provider-independent or portable address space, BGP sessions at multiple locations, health-linked announcements, consistent configuration across sites and monitoring from many vantage points. Remember routing security as well: your authorizations must permit every legitimate origin.

That effort pays off for DNS operators, large platforms and organizations with several sites serving the same stateless service. If you have one location, or your application depends heavily on a single shared database, anycast adds complexity without solving your actual bottleneck. Start by measuring where your users are and where the delay comes from; distance sets a floor on latency, and anycast helps only by shortening it.

Common questions

Can two users see different content from one anycast address?

Yes, if the sites hold different data or are partway through an update. Operators aim to keep sites consistent, but propagation takes time, so a stale answer from one location is a real failure mode.

Is anycast a security feature?

It improves resilience and spreads attack traffic. It doesn't authenticate the server, so you still rely on protections such as TLS or DNSSEC to confirm that answers are genuine.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in IP Addresses & Routing →

Latest news on this topic