Editing Your Hosts File In Windows

Andrew Nacin mentioned here at WordCamp San Francisco 2011 where your hosts file is on Mac (and Linux), but I thought I’d point out where your hosts file is on Windows and how to change it so that you can point domain names to your local computer.

The easiest solution is to create a shortcut that will open Notepad and then tell it to open your hosts file. Right-click your desktop and select New → Shortcut. Paste the following into the field that pops up:

%windir%\system32\notepad.exe %windir%\System32\drivers\etc\hosts

Once you’re done creating the shortcut, right-click it and select “Properties”. Under the “Shortcut” tab is an “Advanced” button. Clicking it will show a checkbox for “Run as administrator”. This is important because otherwise you won’t be able to save your changes as the file is a protected one.

Opening it will show a little documentation and some examples. If you want to add your own, just add it to the bottom in this format:	yourdomain.com

Saving the file and then visiting the domain in your browser will now show you files served by your local development environment. Note: a hard refresh may be required to due to your browser’s DNS cache. This can be accomplished by pressing control and F5.

This post was updated to recommend using a shortcut instead of manually opening Notepad as an administrator.

11 thoughts on “Editing Your Hosts File In Windows

  1. Pingback: Editing your hosts file in Windows | william p. davis

  2. I would hope any and all web developers would know how to do this… but then again, so called “security experts” suck… :S

  3. I wanted to add that in my experience, I either have to close the browser and reopen it if it cached the IP, or use a different browser.

    Thank you for the summary of best practice for editing the hosts file in Windows. I’ve certainly been doing it wrong so far, by modifying the permissions on the security tab of file properties.

  4. Pingback: Setting up Virtual Hosts with XAMPP running on Windows 7

  5. Pingback: Just followed the rest of the Installing GitLab… « GlacierAgWeb

  6. Minor improvement (at least for me): Notepad++ will notice that the file is read-only and offer to re-open itself in admin mode.

Comments are closed.