I've read How can I send visitors to the closest server using DNS? post, but there's still some thing, on a practical level that I don't understand.

Say I have two servers. One in NY another in Paris. Both of them have different IP adresses, and which were assigned to them by the ISP (or hosting companies)

Which steps do I need to follow so that people in Europe, when they type http://blabla.com:8080 will be translated to the IP of the nearest server with respect to the client?

My final goal is to increase the speed of a TCP-Socket application I've written, by directing users to the nearest server.

UPDATE: Thank guys for the answers. I guess there's a lot more for me to learn :\ before I can actually achieve this.

  • 1
    What you're looking for is commonly called GeoDNS. Some less commonly used DNS server have their own "unique" names for the technology. – Chris S Mar 21 '13 at 0:00

Amazon AWS's Route53 is a reliable and well priced global load balancer which utilizes anycast. This is by far the simplest route.

If you want to set up anycast DNS yourself you would need to obtain an IP address and have multiple datacentre locations advertise this IP address in their BGP. Typically people purchase IP address ranges from their relevant authority however I have seen some datacentres that are willing to lease people IP addresses and allow them to advertise them from other datacentres.

The typical set up is that each server has both its own unique IP address and an anycast address. For example:

London has and NY has and

A DNS server runs on each server listening on and issues the unique IP for that server.

Remember that anycast is at the IP layer and thus below transport technologies such as TCP. As such, any transport that tracks state (e.g. TCP) is not suitable for anycast. DNS is (usually) UDP and is used as a method of distributing clients to their closest server to make a TCP connection.

  • 1
    It's somewhat misleading to say that TCP is not suitable for anycast. As long as the routing doesn't change during a TCP session, you will be fine. In typical usage, the routing doesn't change often (e.g., not ever, except during an outage or maintenance). For many applications, TCP sessions are short-lived. "Classic" web technologies typically used short-lived HTTP connections, for example, although newer techniques may leave connections open longer. – Dan Pritts Jun 11 '15 at 14:24
  • Definitely agree though BGP is changing routes all the time as various carriers have issues. Although it would ordinarily work, there are occasions when it will not work. It may be better to say that TCP is suitable for anycast, providing the application layer protocol can handle connections dropping. – phil-lavin Jun 11 '15 at 15:25

You need to use a service that will base the DNS response on their location. Either outsourced to a DNS company or built yourself. I think the technology you are really looking for is Global Server Load Balancing (GSLB), not AnyCast.

Most DNS companies offer this as a service.

PowerDNS seems to be a popular solution for DIY GSLB: http://www.powerdns.com/auth.html


If you have only two servers, one in North America, and another in Europe, then you could decide to run both your TCP-socket app and your DNS yourself.

With DNS, you could use something like the Split-Horizon DNS approach, which could either be achieved through integrated functionality of your DNS server, or through a firewall that would redirect different IP-address ranges to different running instances of your server (you could run two different copies of the server on your local machine, which will listen at different local IP-addresses).

Having only one NA and one EU host, you could probably get expected results in ≈90% of cases by replying to DNS requests from RIPE and AfriNIC IP-addresses with an A record of your host in Europe, and requests from the IP-addresses from the /8 blocks administered by ARIN, APNIC, LACNIC and the rest of the /8 address space with an A record of your server in North America. This will have some wrong results in certain situations (some /8 blocks are shared between Europe and North America, some address space is anycast etc), but the worst that would happen is a little bit of extra latency to the affected party, so, it shouldn't be a big deal.

(And, yes, there should be a way to make these things easier, but, so far, it seems like there is none.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.