As I mentioned in my last post, there’s a loophole inherent in how routers forward your packets around the Internet—specifically, routers are next-hop forwarding: your data is sent as a stream of packets to a router, and it looks at its routing table and decides where the packet should go next.
A route is just an entry in a table that says “packets for 192.168.250.1 should be sent to this IP address, which will send it to the right place for you.” On the last router before the host, the route says “192.168.22.8 is right here, so just send it to the MAC address associated with that IP straight away.”
So here’s the first half of the loophole: Each router decides for itself what the routing table looks like. There’s nothing saying that two different routers can’t *both* have totally different routes to a particular IP. Whichever route you take depends entirely on which router your packets go through on the way to the destination. This is inherent in how IP networks work.
Here’s the second half of the loophole: there’s nothing that says that an IP address has to be unique to a particular machine or network interface.
Put those two together, and you’ve got the basics of anycasting: two different servers, in two different cities, both own 192.168.250.1. The router each server is plugged into knows that IP is right there, and because routers need to know what the other router does in order to be useful, each router knows that there is *another* route to that same IP via the router in the other city.
The routers talk either talk to each other via an Interior Gateway Protocol (basically, they each say “these are all the routes I have”), or they’re statically configured to know about each other. You actually have to do this for anything to work.
And if your network is sane, any overlapping routes have a concept of metrics: that is, how much does it “cost” to go from here to there. The cost of a connected route is (by default) 1. The cost of anything else is going to be higher—because there’s the other side’s “1”, plus the cost of the link (in this case, the link between the two cities). So whichever router has a better metric is the one that will be used.
But all this is transparent. You’re still just talking to 192.168.250.1, but that IP is “owned” by lots of servers, and the routers decide which way to send the traffic (that is, they do their jobs :-)).
Now, it’s not quite that simple to implement this. You’ve got to have a sane network—one with a properly configured IGP—and you’ve got to have some way to “watch” the service.
More on that in the next installment:
- Anycast: Networking Introduction
- Anycast: The Loophole
- Anycast: The Interface
- Anycast: Handling Routes
- Anycast: DGRAM vs. STREAM
- Anycast: IP-SLA HOWTO