/dev/trouble
Eric Roller's Development Blog

This blocking effort appears to have started in the Windows world but it is applicable to all UNIX-based systems where a hosts file is used.

Basically, copy the contents of this example hosts file to the end of your /etc/hosts file (requires root access).

[more]

In /etc/hosts, make sure not to remove the pre-defined settings, but you may comment out the duplicate "127.0.0.1 localhost" line. It should look similar to this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost

# Custom entries (not shown)


# This MVPS HOSTS file is a free download from:            #
# http://www.mvps.org/winhelp2002/                         #
#                                                          #
# Notes: the browser does not read this "#" symbol         #
# You can create your own notes, after the # symbol        #
# This *must* be the first line: 127.0.0.1     localhost   #
# *********************************************************#
# ---------------- Updated: Sept-02-2009 ------------------#
# *********************************************************#
#                                                          #
# Entries with comments are all searchable via Google.     #
#                                                          #
# Disclaimer: this file is free to use for personal use    #
# only. Furthermore it is NOT permitted to copy any of the #
# contents or host on any other site without permission or #
# meeting the full criteria of the below license terms.    #
#                                                          #
# This work is licensed under the Creative Commons         #
# Attribution-NonCommercial-ShareAlike License.            #
# http://creativecommons.org/licenses/by-nc-sa/3.0/        #

##DUPLICATE:
##127.0.0.1  localhost

#start of lines added by WinHelp2002
# [Misc A - Z]
127.0.0.1  fr.a2dfp.net
127.0.0.1  m.fr.a2dfp.net
127.0.0.1  ad.a8.net
[...]

Finally, remember to check the example hosts file for updates; it is updated quite frequently.

To automate this process, I have created this script. You would need to execute it with "sudo" (or it could be placed into /etc/periodic/monthly ?).

#!/bin/sh
# File: 900.host_db_update

echo "Started /etc/hosts update"

# Download the current version without progress info:
curl -so /tmp/hosts.zip https://winhelp2002.mvps.org/hosts.zip

if [[ -s /tmp/hosts.zip ]]; then
    # Unzip quietly and convert CRLF -> LF
    unzip -aoqq -d /tmp /tmp/hosts.zip HOSTS
    rm /tmp/hosts.zip
fi

if [[ ! -fs /tmp/HOSTS ]]; then
    echo "Error: Download of hosts file failed."
    rm -f /tmp/HOSTS
    exit 1
fi

tmpdate=$(grep -m 1 Updated: /tmp/HOSTS|awk '{print $4}')
etcdate=$(grep -m 1 Updated: /etc/hosts|awk '{print $4}')

if [[ "$tmpdate" == "$etcdate" ]]; then
    echo "Info: Hosts file is already up-to-date ($etcdate)"
    rm -f /tmp/HOSTS
    exit 0
fi

# Remove the previous MVPS additions from /etc/hosts
sed '/^# This MVPS HOSTS/,$ d' /etc/hosts > /tmp/hosts.new

# Append the new settings
sed '/^[^#].* localhost$/ s/^/##/' /tmp/HOSTS >> /tmp/hosts.new
rm /tmp/HOSTS

# Make a backup and move the new file:
cp /etc/hosts{,~}
mv /tmp/hosts.new /etc/hosts

# Print a message:
echo "Updated /etc/hosts with settings from $tmpdate"
exit 0