How to edit your hosts file on a Mac Operating System

  • 07-07-2010 9:29 AM

Your computer resolves domain names (yoursite.com) to IP addresses via DNS service. The hosts file overrides this and allows you to hard code an IP address for your domain name for temporary testing purposes.

To open the file, do the following steps

1. ks_command.gif Command + Space will bring up your Spotlight search (Magnifying glass in the upper right of your screen)

2. Start typing "terminal".

terminal.jpg


3. Select the terminal application

terminal icon

Note: The Terminal is a program included with all versions of Mac OSX When launched, it provides a command line to control of the UNIX based operating system.

4. Copy and paste this command: osascript -e 'tell application "TextEdit" to open "/etc/hosts"'

5. Edit the file to include the temporary IP address and domain name, save the file.

Note: The formatting of this file is critical. Each line may have one IP address followed by a [tab] and multiple domain names separated by a space.
Example Line: 66.185.125.12          yoursite.com www.yoursite.com

6. Flush the DNS cache by typing this command in your terminal window:
dscacheutil -flushcache

Your domain name should now resolve to your hard coded IP address. When you are done testing be sure to open the hosts file again and remove the lines you added.


  Print


Comments


  Add Comment

Confirm Submission

Please enter the text from the image in the box provided, this helps us to prevent spam.