Why does Apple’s website break with 2o7.net blocked

safari

I have an /etc/hosts block on 2o7.net and it seems that Apple's metrics.apple.com is a DNS alias for 2o7. When navigating apple.com with Chrome or Safari, I get the following:

Failed to load resource: the server responded with a status of 404 (Not Found) 
http://metrics.apple.com/b/ss/appleglobal,appleusmac,appleusmacbookpro/1/H.…er%3BQuickTime%20Plug-in%207.7.1%3BSharePoint%20Browser%20Plug-in%3B&AQE=1

Whenever I get this message Javascript seems to break and pretty much even link on the site is ignored. I'm not sure if this is a browser bug.

I don't want to unblock 2o7.net but would obviously like the site to work. Any ideas?

Best Answer

dig metrics.apple.com gives

;; ANSWER SECTION:
metrics.apple.com.  4107    IN  CNAME   appleglobal.112.2o7.net.
appleglobal.112.2o7.net. 249    IN  A   66.235.133.14
appleglobal.112.2o7.net. 249    IN  A   66.235.138.2
...

so you could try to dynamically update your hosts file every hour or so:

grep -v metrics.apple.com /etc/hosts > /tmp/raw-hosts
echo $(dig metrics.apple.com | 
       grep ^appleglobal | 
       head -1 | cut -c 35-) metrics.apple.com appleglobal.112.2o7.net >> /tmp/raw-hosts
mv /tmp/raw-hosts /etc/hosts