Modify your hosts file in Windows 10
Here’s how you can modify Hosts files in Windows 10, and map domain names to server IP addresses of your choice.
- Open Notepad with administrator privileges
- Browse to C:\Windows\System32\drivers\etc\hosts (Or paste this into the address bar)
- Open the file
- Make your changes
Applies to All Windows 10 Versions
Windows 10 still retains the old computing standard of having a hosts file for rudimentary hostname mapping. In simpler terms, the hosts file provides a mechanism to map domain names (such as “onmsft.com”) to server IP addresses of your choice.
Windows refers to the hosts file each time it connects over a network using a hostname. If it finds an entry for the hostname in the hosts file, it will contact the server specified in the file. Otherwise – and in the vast majority of cases – it will resolve the hostname using DNS (domain name service), which is the process used on the Internet to obtain the server IP address behind a domain name.
While it may sound technical, the hosts file is a really simple approach to network routing – and it’s easy to add your own entries. To get started, you just need to open the file. It resides in Windows’ internal “System32” folder, so to save your edits you’ll need administrator access.
The quickest way to open the file is using Notepad with administrator privileges. Search for Notepad (press the Start button and type its name) and right-click the app to display the context menu. Click “Run as administrator” to launch a privileged instance of the app. Note you may need to reauthenticate yourself or get an administrator’s password if you’re not already logged in as one.
With Notepad open in administrator mode, you’re ready to open the file. Click File > Open and browse to the file at C:\Windows\System32\drivers\etc\hosts (you can copy and paste this into the address bar at the top of the Open window). If you do browse through the folders graphically, remember to change the file type filter to “All Files” so the hosts file shows up.
Now you’re ready to edit the file. If you’ve never opened the hosts file before, all you’ll see is a short section of text describing its purpose and how to make edits. The introduction provides a useful overview of how the file is structured, but we’ll cover the basics here.
The hosts file is a simple mapping of IP addresses and hostnames. Each entry goes on a newline, with the IP address (that’s the numerical address) first, followed by a space or tab character and then the hostname (or domain). You can add comments to the file by placing a “#” character at the start of the line – this will make Windows ignore the line when reading the file.
Therefore, if you want to point “microsoft.com” to the IP 18.104.22.168, you’d write “22.214.171.124 microsoft.com” on a new line. Each time you try to visit microsoft.com, you’ll find yourself instead at the (non-existent) 126.96.36.199 website.
At this point, you may be wondering why you’d ever need to edit the hosts file. While it is more useful to technical users, there are also a few more general cases in which it might have value. One example is if you wanted to block a certain website, for example Google. By adding an entry for “google.com” to the hosts file, you can force Windows to point the address to a different location – so users won’t be able to visit the site.
To achieve this example, add a line such as “0.0.0.0 www.google.com” to the file. Save the file and try and visit Google in your browser. You should find the site fails to load.
Remember that this is a far from infallible way to block a site – another user could simply reverse the hosts file edit themselves. In addition, some software may employ its own techniques to lookup hostnames which might ignore the hosts file.
One far more realistic application of the hosts file is to block websites which serve up ads or spyware. Although we won’t be listing any here, if you map the addresses of prominent ad providers to an unused internal IP address (such as 127.0.0.1), you’ll suddenly be browsing an ad-free internet – in every browser.
Windows will resolve the ad URLs to an address that no longer points to the providers’ servers. Just remember that every address you add must be the hostname only (example.com), not the full web address (http://www.example.com).
That’s all about the hosts file. While you’re unlikely to use it outside of a development or network environment, it does have practical applications which could be of use to every PC consumer. You should also know that the hosts file also exists on Mac and Linux systems with the same syntax, albeit in a different location.Further reading: howto, Windows 10, Windows 10 Howto