Step 1 – Open the Terminal.app
Either start typing
Terminal in the Spotlight search, or goto Applications > Utilities > Terminal.
Step 2 – Open the host file
Open the hosts file by typing the following in the Terminal window:
sudo nano /private/etc/hosts
Type your user password when prompted.
Step 3 – Edit the hosts file
The hosts file contains some comments (lines starting with the # symbol), as well as some default hostname mappings (e.g. 127.0.0.1 – local host). Simply append your new mappings underneath the default ones.
Step 4 – Save the hosts file
When done editing the hosts file, press
Ctrl O to save the file.
Press Enter on the filename prompt, and
Ctrl X to exit the editor.
Step 5 – Flush the DNS cache
You can use a simple Terminal command to flush the DNS cache, and have your host file changes take immediate effect. Using the open Terminal window, then the following command:
Your new mappings should now take effect.