Use the following steps -
- Launch Terminal, type sudo nano /private/etc/hosts and press Return. You’ll need to also enter your admin password to execute it, as with all sudo commands.
- You will now have the hosts file open in the Nano editor. Use the arrow keys on your keyboard, to navigate and edit the file.
- Go to the bottom of the file and add the desired IP followed by the host name (or domain name). Save the file and you are all set.
- Use your Web browser to test the changes and flush the cache with dscacheutil -flushcache if they still haven’t taken into effect.
For complete reference on windows, MAC and Linux use the following link.
How to edit hosts file