working around [slow] adservers, updated

In an earlier entry, I mentioned some simple steps to prevent slow loading ads from blocking page loads. I neglected the one step that makes the others effective. You need to make sure you look up any hosts in the local file you just updated.

So to finish this task, vi /etc/lookupd/hosts and make the file’s contents look like this:

LookupOrder Cache FF NI DNS DS

Feel free to make a backup. What this tells the networking infrastructure is to look in the cache (names we have already looked up), the NetInfo database, the local flat files (like /etc/hosts), our local DNS server(s), and any Directory Servers we have configured. Since you have now equated some adservers with the loopback interface, they’ll never be looked up again.

And one more note: extracting/inserting information with nidump/niload is pretty easy, but I have tripped myself up a couple of times.

nidump hosts / > hosts will dump the currently loaded hosts (or /machines directory in NetInfo) to a file called hosts.

It will look a lot like this:

127.0.0.1 localhost
127.0.0.1 ad.doubleclick.net
127.0.0.1 ad.doubleclick.com
127.0.0.1 ar.atwola.com
127.0.0.1 media.fastclick.net

To get it back into NetInfo can be done a couple of ways. If you’re only adding new hosts or editing existing ones, this incantation should work.

niload -v -m hosts / < hosts: the v and m flags are for verbose and merge: you are merging in, rather than creating new entries.

If, on the other hand, you’re removing entries, use this:
niload -v -d hosts / < hosts: the d flag will delete all current entries in /machines and repopulate that directory with the file contents you specify.