Using a dnscache proxy to get faster AppleTV movie downloads and still use OpenDNS
Since buying the new AppleTV a few months ago, I've been disappointed in how long you have to wait for your movie download to be ready for viewing. I get about 10Mbps download speeds through Comcast, and use OpenDNS, so shouldn't it be faster than 15-20 hours? Changing from HD to Standard definition has helped a bit, but you still have to come back later to watch your movie.
Today I came across this story on Slashdot that identifies the problem: Akamai, the CDN that Apple uses to distribute its content, does geolocation on the DNS request to determine the IP of the server you should download your movie from. By using a 3rd party like OpenDNS or Google for your DNS service, you'll get the IP of the server closest to that DNS server, not the closest one to you. Makes sense, this is how many CDNs work.
Since I have a home linux server doing NAT, DHCP, and some file serving, I figured I would just just proxy my DNS through dnscache to solve this problem. The idea is to send only any Akamai related DNS requests through my ISP's servers, and send everything else to go through OpenDNS. And it works! I'm watching Inception, in HD, minutes after downloading it. Here's what I did to get it working.
First, I looked up the DNS servers comcast assigns me, which are 68.87.76.182 and 68.87.78.134. I then set up dnscache to run on my server's internal IP, 192.168.1.1.
Next, after updating my dhcp server to point clients to this IP, I started watching my DNS logs to see what domain names are used by my AppleTV. Since dnscache logs are not completely human readable, I used this script to parse them. The second level domain names I came up with are: akadns.net akadns.org akamai.net akamaitech.net akam.net, and edgesuite.net. I'm not entirely sure which ones I need, so I just decided to proxy them all.
Now, I just needed to tell dnscache, located in /var/service/dnscache, where to send traffic. There are 3 things to do to accomplish this:
- Tell dnscache to forward all requests to external caches by putting 1 in /var/service/dnscache/env/FORWARDONLY
- Set the default resolvers to OpenDNS replacing the existing root server IPs in /var/service/dnscache/root/servers/@ with those from OpenDNS, 208.67.222.222 and 208.67.220.220.
- Tell dnscache about the Akamai domains I want to go to Comcast's DNS servers. To do this, just put the Comcast IP addresses in files representing each domain name in /var/services/dnscache/root/servers/akamai.net, /var/services/dnscache/root/servers/akadns.net, etc.
Once I restarted dnscache, I checked the logs to make sure traffic was going to the right places. By this point, I'm about 25 minutes into my movie, and though it has had to rebuffer a couple of times, it's considerably better than it was before the change. Now I can still benefit from the performance of OpenDNS, but get reasonable iTunes performance as well.
November 17th, 2011 - 18:14
Thanks Bill, this is just what i’ve been looking for.
Regards,
Nelson