From my understanding CDN are fast because they have big pipes, serve static content and are 'close' to you. But from my understanding DNS's give you a random IP address. If a CDN have 1 location across your street, another 100 miles away and many locations halfway around the world how does one get a (rare) close one and not a (many) far away server?
closed as off topic by Chris S Sep 9 '12 at 18:35
Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.
DNS servers usually give you the address from the closest datacenter to you. When your DNS resolver (or your ISPs if you're using that) asks the CDN's dns server for an ip address, it checks the IP from where the request came, and returns the IP address(es) closest to there.
So if you're using an ISP in France, and try to resolve example.com, its nameserver sees that the request came from France, and returns addresses closest to there.
Try resolving some CDN's address (for example facebook photos):
If I check the whois on those IP addresses, i get the location as Germany (closest akamai datacenter to my location). If you're from somewhere far from Germany, you should get a different response.