Here are instructions on how to edit the Hosts file:
http://www.simplehelp.net/2012/01/25/how-to-edit-the-hosts-file-in-os-x-lion-the-very-easy-way/
The default hosts file will look like 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
To block a site, say
www.Mackeeper.com, add the following line to the hosts file after the line "255.255.255.255 broadcast host":
0.0.0.0
www.mackeeper.com
so that the hosts file now reads:
##
##
# 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 broadcast host
0.0.0.0
www.mackeeper.com
::1 localhost
fe80::1%lo0 localhost
Save the file then restart the computer (or flush the DNS cache by entering the following line into terminal and hitting return:
sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder; say cache flushed
Restart your browser and you should find the site is now blocked.
You can block as many sites as you want by adding them on separate lines as above.