When you ping 1.1.1.1 from Tokyo and from Frankfurt, you reach two different servers, yet the IP address is the same. That’s anycast: the same IP prefix is announced from many locations, and the internet’s routing delivers each user to the “closest” one. Anycast powers public DNS resolvers, root DNS servers, CDNs and DDoS protection networks.

Unicast, anycast, multicast and broadcast

Type One address reaches…
Unicast Exactly one host (the normal case: your VPS’s IP)
Anycast The nearest of several hosts sharing the address
Multicast A group of subscribed hosts
Broadcast All hosts on a local network

How anycast works

The internet routes between networks (autonomous systems) with BGP. Each network announces which IP prefixes it can reach. With anycast, the same prefix (say 198.51.100.0/24) is announced from data centres in many cities. Routers everywhere pick the best path according to BGP. That usually means the fewest network hops or a preferred peering, which typically, but not always, is the geographically nearest site.

User in Tokyo    ──▶ nearest announcement: Tokyo PoP
User in Paris    ──▶ nearest announcement: Paris PoP
User in Chicago  ──▶ nearest announcement: Chicago PoP

The user does nothing special. The routing system makes the choice. See BGP basics.

Why it’s used

Lower latency. Users connect to a nearby node, so DNS lookups and TLS handshakes to a CDN edge take a few milliseconds instead of a hundred. See latency vs bandwidth.

Resilience. If one site fails, it withdraws its BGP announcement, and traffic shifts to the next-nearest site automatically, usually within seconds to a minute, with no DNS change needed.

DDoS absorption. Attack traffic from botnets around the world is split across all sites instead of concentrating on one. Each location absorbs its regional share. This is a key reason large DDoS mitigation networks are anycast. See DDoS attack types.

Simplicity for users. One easy address (1.1.1.1, 8.8.8.8, 9.9.9.9) works everywhere.

Where you meet anycast

  • Public DNS resolvers: Cloudflare 1.1.1.1, Google 8.8.8.8, Quad9 9.9.9.9.
  • Authoritative DNS providers: Cloudflare DNS, Route 53 and most managed DNS providers serve your zone from anycast nameservers. See nameservers explained.
  • CDNs and reverse proxies: Cloudflare, Fastly and others. Your site’s proxied IP is anycast.
  • Root DNS servers: the 13 root “letters” are each anycast to hundreds of instances.

Anycast vs GeoDNS

Another way to send users to nearby servers is GeoDNS: the DNS server returns a different (unicast) IP depending on where the query comes from.

Anycast GeoDNS
Mechanism BGP routing DNS answers
Requires Your own IP prefix and ASN, BGP sessions at each site A DNS provider with geo features
Failover speed Fast (route withdrawal) Bound by DNS TTL and caching
Accuracy Network-topology “nearest” Based on the resolver’s location (can be wrong for users of distant resolvers)
Good for DNS, CDNs, UDP services, DDoS Simple multi-region web apps

Limits and gotchas

  • Stateful TCP connections: if routing changes mid-connection, packets may reach a different site that doesn’t know the connection. In practice routes are stable enough for short HTTP connections, and operators design around it, but long-lived TCP sessions are a consideration.
  • “Nearest” in BGP terms isn’t always nearest geographically. Peering policies can send users to a distant site.
  • Not something you set up on a single VPS. Running your own anycast requires your own IP prefix (a /24 for IPv4, a /48 for IPv6), an ASN, and providers that let you announce it via BGP in multiple locations. Most sites get anycast’s benefits by using anycast services (DNS providers, CDNs) in front of normal servers.

What it means for your site

A typical, effective setup:

  1. Anycast DNS from a managed DNS provider, for fast, resilient lookups.
  2. A CDN (anycast edge) in front of your origin, for static assets or the whole site.
  3. Origin servers (VPS or dedicated) placed near the bulk of your users or your data. See choosing a VPS location.

Quick reference

Concept Summary
Anycast Same IP announced from many places; BGP picks the nearest
Benefits Latency, failover, DDoS absorption
Used by DNS resolvers, authoritative DNS, CDNs
Requirements to run your own IP prefix, ASN, BGP at each site
Alternative GeoDNS (DNS-based steering)

Related: CDN for your website and DNS propagation.

  • Networking
  • DNS
  • CDN