When testing a website on a new server before public DNS propagation or routing a production domain to a local development environment, the quickest solution is updating the hosts file on your local machine.
On Windows, this file is located in a protected operating system directory. If you simply navigate to the file and double-click to edit it, saving your changes fails with an Access Denied error.
Here is the exact step-by-step procedure to edit and save the file cleanly without permission roadblocks.
1. Where is the Windows hosts file located?#
The hosts file is located at the following absolute path:
C:\Windows\System32\drivers\etc\hosts
Because it resides within the System32 directory tree, modifying it requires elevated Administrator privileges (UAC).
2. Method 1: opening notepad as administrator#
- Open the Windows Start menu and type Notepad.
- Right-click the Notepad shortcut and select Run as administrator.
- Accept the User Account Control (UAC) prompt.
- In Notepad's menu bar, click File > Open.
- In the file picker address bar, paste
C:\Windows\System32\drivers\etc\and press Enter. - In the bottom right corner of the dialog, change the filter from *Text Documents (\.txt) to All Files (\.\)**.
- Select the
hostsfile and click Open. - Scroll to the bottom of the file and add your custom mapping in the format
IP domain. For example:
192.168.1.50 mywebsite.com
192.168.1.50 www.mywebsite.com
- Press Ctrl + S to save.
The file saves immediately without permission warnings.
3. Method 2: quick terminal shortcut (PowerShell or CMD)#
If you prefer using the command line:
- Open PowerShell or Command Prompt as Administrator.
- Run the direct command:
notepad.exe C:\Windows\System32\drivers\etc\hosts
- Notepad will launch with elevated permissions, opening the file directly. Make your changes and save with Ctrl + S.
Conclusion: quick validation and practical tips#
After saving the hosts file, changes take effect immediately. No system reboot is required.
To ensure your web browser and network stack pick up the new mapping without cached DNS responses:
- Flush the local DNS cache in the terminal:
ipconfig /flushdns
- Verify resolution by pinging the configured hostname:
ping mywebsite.com
The output will confirm that traffic resolves directly to the target IP configured in your hosts file.
Was this article helpful?
Leave a quick reaction to help prioritize future technical guides:
This post is licensed under CC BY-NC.



Comments
Join the discussion below.
0 comments