Change hosts file in OS X

type this command in a terminal shell:

sudo vi /private/etc/hosts

It will ask for root password and then you will be able to edit your hosts file in the great VI terminal editor.

After editing hosts fils, clean your DNS cache running this command:

dscacheutil -flushcache

You have to close and open the browser to get new dns settings.
Enjoy.