When you query 1.1.1.1, you are not connecting to a single server โ you are connecting to one of hundreds of servers worldwide, all sharing the same IP address. This is Anycast routing, and it is how modern DNS and CDN providers achieve global scale and resilience.
Unicast vs Anycast
In traditional Unicast routing, one IP address corresponds to one destination. Your packets always go to the same server, no matter where you are.
In Anycast, the same IP address is announced from multiple locations simultaneously. BGP routers direct your packets to the topologically nearest announcement โ usually the closest data center.
How BGP Makes Anycast Work
Each Cloudflare or Google data center announces the same IP prefix (e.g., 1.1.1.0/24) to its upstream providers. When your ISP receives these announcements from multiple sources, it chooses the "best" path based on:
- AS Path Length: Fewer autonomous systems to traverse is usually preferred.
- Local Preference: ISPs may prefer certain peers over others.
- Geographic Proximity: Often correlates with shorter AS paths.
Benefits of Anycast
- Low Latency: Users automatically connect to the nearest server.
- DDoS Resilience: Attack traffic is distributed across all locations. No single point of failure.
- Automatic Failover: If a data center goes offline, BGP withdraws the route, and traffic shifts to the next nearest location โ no DNS changes needed.
- Simple Client Configuration: Users only need to remember one IP address.
Anycast for TCP: The Challenge
Anycast works perfectly for UDP (like DNS queries) because each packet is independent. TCP is trickier โ if routing changes mid-connection, packets might go to a different server that does not have the session state.
Solutions include:
- Consistent Routing: Careful BGP configuration to minimize route flaps.
- Session Affinity: Hashing based on client IP to ensure sticky routing.
- QUIC: Connection IDs survive route changes (see our HTTP/3 article).
Real-World Anycast Networks
Major Anycast deployments include:
- Cloudflare: 1.1.1.1 DNS, CDN, Workers โ 300+ cities
- Google: 8.8.8.8 DNS, Cloud CDN
- Amazon: Route 53, CloudFront
- Root DNS Servers: Most root servers use Anycast
Try our DNS Lookup tool and see which Cloudflare data center answers your queries!