Editing Your HOSTS File (Mac or PC)

I’ve written only a little about the HOSTS file before.  It is basically a holdover from days before Domain Name Service (DNS) was centralized and easy to access.

These days, it normally would only be truly needed on a small internal network or using a virtual private network (VPN) solution where the DNS is not available.  You might need to add a “local” server in order to access it by name, for example.

First, some cautions:

  1. Always make a backup in a safe place.  Messing up a HOSTS file may seriously impact your networking ability!  You need to ensure you can get back to a known state.
  2. Always, always, always use  a text editor to modify it.  Microsoft Word is not a text editor.  If you don’t understand what the difference is, then do not edit your HOSTS file!
  3. The machine you are putting into the HOSTS file needs to have a static IP address.  In other words, the IP address needs to be set up so that it never changes.  Otherwise, adding it to the HOSTS file buys you nothing.

With that out of the way, what editor is advisable, and where is the file located?

Windows PCs comes with Notepad.  While it isn’t the best thing going, it is more than sufficient for the job.  The

Macs come with nano (Nano’s ANother editor).  If you’ve ever used Unix, it is a pico clone.

In either event, I’d suggest opening it from the command line for ease.  It will require administrator privileges, so a Windows Command Prompt should be opened by going to Start | Accessories, right-clicking on Command Prompt and choosing Run as administrator.


Once the Command Prompt window is opened, you can run the following command to edit the HOSTS file:

notepad %systemroot%\system32\drivers\etc\hosts

Finally, the following command will flush the DNS to ensure it hasn’t cached your desired destination name somewhere:

ipconfig /flushdns

On the Mac, you can open up a terminal and ensure you use the sudo command for running the commands.  Sudo will prompt for a password to verify.  The following command should enable you to edit the file:

sudo nano /private/etc/hosts

Likewise, it is a good idea to flush the DNS cache.

sudo dscacheutil –flushcache

That should give you a good idea of the basics in editing the HOSTS file.