How to edit the hosts file in Mac OS X
Posted by .CD Support, Last modified by .CD Support on 04 November 2012 09:31
The hosts file is a text file that maps hostnames to IP addresses.
The hosts file can be edited to block certain hostnames (like ad-serving/malicious hosts), or used for web development purposes, i.e. to redirect domains to local addresses.
Editing the hosts file
Editing the hosts file in Mac OS X – Leopard, is a pretty easy task, especially if you are familiar with the terminal.
Step 1 – Open the Terminal.app
Either by start typing Terminal on the Spotlight, or by going into Applications -> Utilities -> Terminal.
Step 2 – Open the hosts file
Open the hosts by typing on the Terminal that you have just opened:
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 – localhost).
Step 4 – Save the hosts file
When done editing the hosts file, press control-o to save the file.
Step 5 – Flush the DNS cache
On Leopard you can issue a simple Terminal command to flush the DNS cache, and have your host file changes to take immediate effect:
You can now test your new mapping on the browser!