Adding an entry to the hosts file on OS X is pretty straight forward. First, open up terminal and run the following command.
sudo nano /etc/hosts
This will open up the nano editor in terminal.
You can now add entires to the file using the following format:
xxx.xxx.xxx.xxx somedomain.com www.somedomain.com
xxx.xxx.xxx.xxx is the ip address.
When you're finished, press
o to save the file. Press
enter on the filename prompt, then press
x to exit nano.
Now, enter the following command to flush the DNS cache.
sudo dscacheutil -flushcache
Alternatively, if you are using OS X 10.7 or 10.8, you'll want to use this command to flush the DNS cache instead
sudo killall -HUP mDNSResponder