How to edit your hosts file in Windows 10 (and why you might want to do it)

Windows 10 still maintains the old IT standard of having a hosts file for rudimentary host name mapping. In simpler terms, the hosts file provides a mechanism to map domain names (such as “onmsft.com”) to the IP addresses of the server of your choice.

Windows refers to the hosts file whenever it connects to a network using a host name. If it finds an entry for the host name 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 get the IP address of the server behind a name of domain.

While it might sound technical, the hosts file is a very straightforward approach to network routing – and it’s easy to add your own entries. To get started, all you need to do is open the file. It resides in the internal Windows “System32” folder, so to save your changes you will need administrator access.

The fastest way to open the file is to use Notepad with administrator privileges. Find 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 application. Note that you may need to re-authenticate or obtain an administrator password if you are not already logged in as such.

How to edit your hosts file in Windows 10 (and why you might want to do it) - onmsft.  Com - October 15, 2018

With Notepad open in administrator mode, you are ready to open the file. Click File> Open and locate the file in C: WindowsSystem32driversetchosts (you can copy and paste it in the address bar at the top of the Open window). If you browse the folders graphically, remember to change the file type filter to “All Files” so that the hosts file appears.

You are now 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 changes. The introduction provides a useful overview of how the file is structured, but we’ll cover the basics here.

How to edit your hosts file in Windows 10 (and why you might want to do it) - onmsft.  Com - October 15, 2018

The hosts file is a simple mapping of IP addresses and host names. Each entry goes on a new line, with the IP address (this is the numeric address) first, followed by a space or tab character, then the host name (or domain). You can add comments to the file by placing a “https://www.onmsft.com/how-to/#” character at the beginning of the line – this will cause Windows to ignore the line when reading the file.

Therefore, if you want to point “microsoft.com” to the 1.2.3.4 IP address, you would write “1.2.3.4 microsoft.com” on a new line. Whenever you try to visit microsoft.com, you will instead end up on the (non-existent) 1.2.3.4 website.

How to edit your hosts file in Windows 10 (and why you might want to do it) - onmsft.  Com - October 15, 2018

At this point, you might be wondering why you would need to edit the hosts file. While it is more useful for technical users, there are also a few more general cases where it might be of value. An example is if you wanted to block a certain website eg 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 that users cannot visit the site.

To complete this example, add a line such as “0.0.0.0 www.google.com” to the file. Save the file and try to visit Google in your browser. You should find that the site is not loading.

How to edit your hosts file in Windows 10 (and why you might want to do it) - onmsft.  Com - October 15, 2018

Keep in mind that this is a far from foolproof way to block a site – another user might just reverse the modification of the hosts file itself. Additionally, some software may use their own techniques to find host names that might ignore the hosts file.

A much more realistic application of the hosts file is to block websites that serve ads or spyware. While we don’t list any here, if you map the addresses of major ad providers to an unused internal IP address (such as 127.0.0.1), you’ll suddenly be browsing an ad-free internet – in all browsers.

Windows will resolve ad URLs to an address that no longer points to vendor servers. Remember that each address you add must be just the host name (example.com), not the full web address (http://www.example.com).

That’s all on the hosts file. While it is unlikely to be used outside of a development or network environment, it has some handy applications that could be of use to all PC consumers. You should also be aware that the hosts file also exists on Mac and Linux systems with the same syntax, but in a different location.

Share this post: