Ad Blocking with your own DNS Server
I was originally using /etc/hosts and adding entries for domains as I came across major offenders to my eyes (or ears!):
The problem was that too many of the crappy adservers were using multiple third-level domains, ie campaignname.crappyadserver.com, and this means that I would have to add one for each level. It seems that there isn't a simple way to use a wildcard (*) with the hosts file, so i went looking for a better method. It turns out that Mac OS X ships with a great domain name server called BIND. It just takes a few steps to set it up.
I haven't decided whether this is a good thing or not yet. Maybe I'm just bring hypersensitive, but it seems like my connections are a bit slower for the first visit to a given domain (probably only an extra 1.5 - 2 seconds, but enough so that it is noticable). The plus side is that it feels 10 times faster for each sequesntial visit to the same domain, or to any domain that is in the cache. I tend to be working a few main domains at a time, so it's great, but when I go to do a Google search and start to pull up a bunch of new domains and have to wait that extra second. So it probably depends on how you use the internet.Create a file in /private/var/named/ called adblock.zone with the following contents:
Make sure that there is a line break at the end of the file. BIND will complain if you don't
Edit /etc/named.conf and comment out line 17:
Start it up and see if it works:
Check /Library/Logs/named.log for any errors If this all works OK, go to System Preferences -> Network, choose your network connection and choose the TCP-IP tab, and add 127.0.0.1 to your list of search domains (which is probably empty).
For each domain you wish to block, add a line at the end of /etc/named.conf: Reload named:
To Simplify this process and make it easier to add domains as you encounter them, create the following applescript and save it as a script in the script menu, or as an application:
Search The Site: