Every Windows version comes with a special Hosts file which helps resolving DNS records. In addition to your network configuration, the file can be used to define a domain=IP address pairing which will have priority above the value provided by the DNS server. Here is how to edit this file in Windows 10.
The ability to edit the Hosts file is useful in many situations. While doing web development, you can make your computer resolve a domain to a local address. Mapping a network device name to its IP address with the Hosts file will allow accessing the device by its name from File Explorer.
The Hosts file is just a regular text file which can be modified using any text editor. The only catch is that the editor app should be started elevated (as Administrator). The hosts file is located in the system directory, so non-elevated apps will fail to save it.
To edit the Hosts file in Windows 10, do the following.
- In the Start menu, go to Windows Accessories.
- Right-click the Notepad app and select More - Run as Administrator.
- In Notepad, click the File menu - Open, or press the Ctrl + O keys.
- Navigate to the folder C:\Windows\System32\drivers\etc.
- Select "All Files" from the drop-down menu.
- Double-click the hosts file.
- Type the IP address of the domain followed by the domain name you want to use to resolve the remote destination host. Save the file(Ctrl + S).
Use one entry per line. Entries should look as follows:
To test the changes you have made, open a command prompt and use the ping command to see the address in the output.
In my case, the remote address of the google.com domain will be resolved to my local computer.
Your hosts file might be modified by anti-malware apps to block dangerous domains or ads. The popular Spybot - Search & Destroy and Spybot Anti-Beacon apps are known to do this.
We also saw how to block ads using the host file when Edge lacked ad blocking addons. People have also modified it to block many Windows 10 telemetry and data collection servers before Microsoft used tricks to workaround this limitation.
Malware can also use the hosts file to hijack genuine domains so besides the usual admin permission-based protection that Windows has for the HOSTS file, you can also set the Read-only attribute for it. When you need to modify it, simply temporarily remove the Read-only attribute, edit it as Administrator and set it again.
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!