Step 1 – Open application terminal.app

You can open the application writing terminal on the spotlight, or simply go to application » Terminal.

 

Step 2 – Open Hosts File

Open hosts file writing on Terminal:

$ sudo nano /private/etc/hosts

hosts-command-edit-file

 

Step 3 – Edition

The edit or add something to hosts file you can simply add a line like this:

123.123.123.123 yourdomain.comnetorg

edit-hosts-file-mac-os-x

 

Step 4 – Save Changes

When you have finished your changes, press control + o and Enter to save.
Then control + x to exit Nano Editor.

 

Step 5 – Clean DNS cache

You can clean you DNS cache with your terminal running this simple command:

$ dscacheutil -flushcache

Now you can test your change on the hosts file.