Monday, 09 August 2010 14:34

Working with a HOSTS File - Mac and PC Methods

Written by 

Need to update your HOSTS file to point a domain to a different IP address?  Below are instructions for both PC (Windows 7) and Mac (OS X Snow Leopard) platforms.

How to Update your HOSTS file on a PC:

a.  Open Notepad (start -> programs -> accessories -> notepad)
pc_open
b.  In Notepad, open the file c:\windows\system32\etc\hosts (no extension; you will need to choose "All Files" instead of Text files in the browse window)
pc_edit
c.  Add your new IP address / domain lines at the bottom of this file
d.  Save and close Notepad

How to Update your HOSTS file on a Mac:


[Edit: I have found an easier way to do this - the following TERMINAL command will prompt you for your OS X password and launch Text Edit as the root user]

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts

[Edit Again: With OSX Lion, the above command no longer works, use this instead:]

sudo nano /etc/hosts


a.  Open Terminal (Applications -> Utilities -> Terminal)
mac_open
b.  Type this command into Termainal: "sudo nano /private/etc/hosts" (without the quotes)
mac_edit
c.  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).  Simply append your new mappings underneath the default ones. Or edit one of the default values if you know what you are doing!  You can navigate the file using the arrow keys.  When done editing the hosts file, press control-o to save the file.  Press enter on the filename prompt, and control-x to exit the editor.
d.  On Leopard you can issue a simple Terminal command to flush the DNS cache, and have your host file changes to take immediate effect: "dscacheutil -flushcache" (without the quotes)

Read 42388 times Last modified on Thursday, 09 April 2015 15:43

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.