Networking

Anycast Routing Explained: One IP Address in Many Places

By NileVPS Team · Published · 5 min read

اقرأ المقال بالعربي

When you query a public DNS resolver or load a site behind a large CDN, the IP address you reach is probably not a single machine. The same address is announced from dozens or hundreds of locations at once, and the internet quietly delivers your packets to one of them, usually a nearby one. That technique is called anycast. It is one of the main reasons global services feel fast and survive huge traffic floods. This article explains how anycast works, what it is good and bad at, and how you can benefit from it when your application runs on a VPS.

Four ways to address a packet

MethodDelivered toTypical use
UnicastOne specific hostAlmost all normal traffic, including your VPS
BroadcastEvery host on a local networkARP, DHCP discovery (IPv4 only)
MulticastEvery host that joined a groupIPTV, some financial feeds, routing protocols
AnycastOne host out of a group sharing the addressDNS, CDNs, DDoS mitigation

With unicast, an IP address belongs to one network interface. With anycast, several servers in different places are configured with the same address, and routing decides which one receives each packet.

How anycast actually works

The internet's routing between networks is handled by BGP (Border Gateway Protocol). Each network, called an autonomous system (AS), announces which IP prefixes it can reach. In an anycast setup, the operator announces the same prefix, for example 192.0.2.0/24, from many data centers.

Routers along the way receive several paths to that prefix and pick one according to BGP policy: shortest AS path, local preferences, peering agreements and so on. The result is that traffic usually lands at a topologically close site. Note the word topologically: BGP measures network paths and business relationships, not kilometers. A user can occasionally be sent to a farther location because their ISP has a cheaper or preferred route there.

If one site goes down, it stops announcing the prefix. Within seconds to minutes, routers converge on the remaining paths and traffic moves to the next best site, without any DNS change.

Where anycast shines

  • DNS: queries are small, mostly single UDP packets, and stateless. This is the classic anycast workload; the DNS root servers and most large resolvers and authoritative DNS providers rely on it.
  • CDNs and edge networks: an anycast address lets a visitor reach the closest edge without needing DNS-based geolocation. Our article on what a CDN is covers the caching side.
  • DDoS absorption: attack traffic from a botnet is spread across all sites instead of concentrating on one, so each location only sees a share of the flood.
  • Simple failover: removing a site is just withdrawing a route.

Where anycast struggles

  • Long-lived TCP connections: if routing changes mid-session, packets may suddenly reach a different site that knows nothing about the connection, and it resets. In practice routes are stable enough for web traffic, but long downloads, WebSockets or VPN tunnels can feel it.
  • Stateful applications: every site needs the data to answer correctly. That is easy for cached files or DNS zones and hard for a database that accepts writes.
  • Debugging: "the server" is really many servers, so a user's problem may only exist at one site you cannot easily reach.
  • Not truly nearest: as noted above, BGP chooses by policy, so latency is good on average, not guaranteed for every user.

Seeing anycast in action

Many anycast DNS servers will tell you which instance answered. From a Linux machine:

dig @k.root-servers.net hostname.bind chaos txt +short

Run it from servers in different regions and you will see different instance names for the same IP address. Comparing mtr -rw 193.0.14.129 (the address of k.root-servers.net) from, say, Europe and Singapore shows completely different paths ending at the same IP.

Can you run anycast on a VPS?

Running your own anycast network requires:

  1. Your own IP prefix (at least a /24 for IPv4 or a /48 for IPv6 to be widely accepted on the internet).
  2. An autonomous system number from a regional registry.
  3. BGP sessions with a provider at every location, so you can announce the prefix yourself.

Typical VPS plans give you provider-assigned addresses and no BGP session, so self-hosted anycast is usually out of reach and, honestly, unnecessary for most projects. You can still get most of the benefit:

  • Use an anycast DNS provider for your domain. Most managed DNS services already answer from anycast networks, which speeds up the first lookup for every visitor.
  • Put a CDN or proxy in front of your VPS. Visitors connect to a nearby anycast edge, and only cache misses travel to your origin.
  • Deploy several VPS instances in different regions, such as Europe, the USA and Singapore, and use GeoDNS or health-checked DNS records to send users to the closest healthy one. This is not anycast, but it solves the same problem for stateful apps.

If you want to build a multi-region setup, you can compare regions on our pricing page and start with one server close to most of your users.

FAQ

Is anycast the same as load balancing?

Not exactly. Anycast spreads users across sites according to network routing, not according to server load. A busy site keeps receiving its share of traffic unless the operator withdraws or adjusts its route, so anycast is often combined with local load balancers inside each site.

Does anycast work with TCP?

Yes. Most CDNs serve HTTPS over anycast every day. Problems only appear when a route changes during an open connection, which is uncommon. Very long sessions are the most exposed.

Do I need anycast for a small website?

No. A single well-placed VPS behind an anycast DNS provider and, if needed, a CDN gives small and medium sites nearly all the practical benefits without the cost and complexity of running BGP.

Related guides