/etc/hosts

10 July 2008

/etc/hosts

I’ve been a big fan of Dan Pollock’s replacement /etc/hosts file for blocking bad things on the internet, but for one reason or another never got around to automating the update process.

I don’t know why, it’s pretty straightforward to pull together a shell script:


#! /bin/sh
tdy=`date +%Y%m%d%H%M`

sudo curl http://someonewhocares.org/hosts/hosts -o /etc/hosts.$tdy.tmp
sudo cp /etc/hosts /etc/hosts.$tdy
sudo mv /etc/hosts.$tdy.tmp /etc/hosts

… and then add it to crontab to run every few days. This will create a backup of the previous /etc/hosts file in case anything goes wrong.

You can also switch ads back on by keeping your original /etc/hosts file around with:


#! /bin/sh
sudo cp /etc/hosts /etc/hosts.tmp
sudo cp /etc/hosts.original /etc/hosts

I keep these in ~/bin/hosts, because I’m like that.

(Some days, UNIX actually works for me. Hallelujah!)

Computer Log | MacBook Log

This is: brett's logjam → /etc/hosts.