Hosts file is an important system file which maps the host/site names with its IP addresses. Basically, it translates the hostname to IP and IP to hostname. In other Words, the hosts file is similar to using a phone book to find the matching phone number of a specific person’s name. Hosts file is a plain text file without any file extension. On Windows computer, We can edit hosts file on Windows 10 For custom domain redirects, block websites, or remove malicious entries set by malware. It functions like a local copy of a DNS server.
Windows 10 Pro x64 2004 - 19041 - 264 XP/Vista/Win7/Win8.1 in VM for testing New 02 Jan 2018 #3 Technically 0.0.0.0 is the network segment broadcast address and 127.0.0.1 is the current device. The Hosts file (also referred to as etc/hosts) is a text file used by Windows (and other operating systems) to map IP addresses to host names or domain names. This file acts as a local DNS service, for your local computer, and it overrides the mappings from the DNS server that your computer is.
Post Contents :-
- 1 Edit hosts File on Windows 10
Edit hosts File on Windows 10
While Domain Name System – or DNS – is mostly used for this function (being a centralized and half-automatically managed name resolution system), the HOSTS file can be used as a local name resolution mechanism, and when used in conjunction with other name resolution mechanisms such as DNS, the HOSTS file takes precedence over them.
Location of the Hosts File
In Microsoft operating systems, the HOSTS file is located in the following location:
C:WindowsSystem32Driversetc
How To Edit Hosts file
Some Times we need to edit the Hosts file, For Different purposes like custom domain redirection, block certain websites, or remove malicious entries set by malware. We can modify the host files using Notepad but, As This is a system file we cant modify this with normal user account, We need administrator rights. For this we need to open Notepad As ( Admin )
Click on the Start menu, Type notepad From Search Results right-click on Notepad and select Run As Administrator. Here on notepad click on file, Select open and Browse for the following path : C:WindowsSystem32Driversetc
Here Select All Files from the drop-down menu and double click on hosts file.
This will open Host files As Shown Bellow image. Here you can custom Redirect domain names, Block Certain websites ( Domain ) or remove malicious entries set by malware.
Note: To modify the hosts file, you need to add two entries, including the IP address of the remote host or application to a the friendly address you want to use. for ex: Type the IP address of the remote host or localhost followed by the domain or computer name you want to use to reach the device or application. Then Click on File, and select Save.
How the Hosts File Works
The Host File contains lines of text that are made of IP addresses followed by one or more host names or fully qualified domain names (FQDNs). Each field is separated by white space (blanks or tabulation characters).
For example, if you wanted to use the HOSTS file to translate a hostname of a computer called “FTPserver” into the IP address of 192.168.1.100, Then We need to Add Bellow line:
192.168.1.100 FTPServer
The HOSTS file can also translate Fully Qualified Domain Names (or FQDNs) of computers, such as ones used on the Internet.
For example, if you wanted to add a manual line to translate an FQDN of a computer called “webserver.domain.com” into the IP address of 11.06.23.100 you would add this line:
11.06.23.100 webserver.domain.com
When you ping it, your computer will resolve the name to the correct IP address:
Redirect a Website Using Host File
You Can Redirect Any Website to Another website by modifying the Host file. For Ex: you want your To Redirect YouTube.com to Twitter.com Means when you open Youtube.com on your web browser it automatically redirects to twitter.com.
For this first we need the Twitter’s IP address. we can Get this by using the ping command. Open command prompt by click on Start type cmd and hit the enter key. Now type ping twitter.com -t you will see the twitter.com numeric IP address.
Now on Host file Add the Twitter IP Space and The Domain Name
104.244.42.193 youtube.com
This line tells our computer to connect Youtube.com to Twitter’s IP address. Type Youtube.com you’ll end up at Twitter!
Create Website Shortcuts using Host file
You can also modify host file to create “shortcuts” that quickly access websites from any program on your computer. For example, if you’re a Twitter addict, you can associate “t” with Twitter – type t in any web browser’s address bar and you’ll instantly end up at Twitter.
You can also create shortcuts with multiple letters, such as twit. You don’t need a .com, .net, .org, or any other type of extension. However, you can’t use spaces.
To do this, just add the following line to the hosts file and save it:
104.244.42.193 t
Now you can type t into any program’s address bar and you’ll end up at twitter.com.
Block website using Hosts file
If you want to block your computer from accessing certain websites, you can use the loopback address (127.0.0.1) followed by the domain name (e.g., 127.0.0.1 website.com)
simply add the following entry on Host file and save.
127.0.0.1 blocksite.com
Ex : 127.0.0.1 facebook.com
127.0.0.1 youtube.com
Remove malicious entries set by malware
Also Sometimes Due to Virus / Malware infection you may notice certain Websites not open on your computer. This is Because malware automatically edits your Host file and make Different entries for Domain Redirection (Ex: Any domain Name automatically Redirect to specific Website ) or Block some websites.
Simply open Host file on Notepad and Clear Other entries set by Malware adware. And left the default entries as shown bellow host file.
Lock Hosts file to prevent hijacking
As sometimes malware/ Adware redirect web address by altering your host files. A good latest updated antivirus can prevent this hijack but if you want to add another layer of security then the second option is to lock the hosts file so no other program or user except you can rewrite to it without unlocking it.
To prevent Host file hijacks, you may navigate to it, right-click on it, select Properties and make it a Read-only file. This will lock down your Hosts file and prevent anyone or any malware from writing to it.
That’s All About edit hosts file on Windows 10. Note that after making any modification on Host files Restart windows to take effect the changes you have done. I hope now you can easily Modify, Edit hosts file on Windows 10 to Custom Domain Redirection, Block Different Websites etc. Feel any Difficulty while edit host files discuss on comments below.
There are several ways to block websites on your Windows PC, but the easiest of them is by editing the native hosts file. Few lines of code and you can block any website, malware, annoying ads seamlessly on your entire machine. However, as simple as it sounds, the process is quite tedious and chances are you might corrupt the hosts file altogether.
So generally, there are many ways to edit and create hosts files and many popular hosts file editor in Windows 10. The conventional way is to manually edit the hosts file and here is how you do it.
Manually edit Host Files
Just a heads up, If you are not comfortable with huge lines of code and the idea of editing configuration files, kindly skip to the next method. Manually editing hosts file is tedious because you cannot directly edit the hosts file in its original location, if you did, you will get an error like ” you don’t have permission to save hosts file windows 10″. So, we’ll have to move it from the below-mentioned location to the Desktop.
You will need Administrator privileges for this activity
After you have moved the hosts file, double click on it. Since the hosts file doesn’t have an extension, Windows doesn’t know which software should be used to open it. Hence, you will see a pop-up asking you to choose an app to open the file. Select Notepad and hit Enter. You will be presented with an editable format of the hosts file which looks like the following screenshot.
Now, the hosts file has several lines of code which are prefixed by a “#”. This means the lines are commented and are of no significance. For our use-case, in order to block a website, we need to enter the website name prefixed by “127.0.0.1” or “0.0.0.0”. For example, if I want to block Facebook.com on my computer, I will attach the following line at the end of the file.
This line ensures that whenever I enter Facebook.com on any browser on my local system, the connection will be redirected to my own IP Address. Since my local system doesn’t have a web server running, I will end up with a “Website not reachable” error message.
Read: How to Find Out What DNS Server Am I Using?
Move the file back to the “C:WindowsSystem32driversetc” location. You will have a pop-up asking for Administrator permissions, just continue with it. Once done, open your preferred web browser, clear cache and now the website will be blocked throughout your system.
Cons:
- Cannot Directly edit the source file.
- No way to have multiple hosts files.
- No option of importing hosts files online.
1. Host File Editor
The problem with the manual method is the complexity of the steps and high chances of rendering the hosts file corrupt. To escape the trouble, you can use a Host File Editor. Host File Editor lets you directly edit the hosts file without moving the original file to and fro. There are tons of Host File Editors available on GitHub but the one I prefer is Hosts File Editor.
Adobe Hosts File Windows 10 Pro
The tool is pretty simple and to the point. You have the old school Excel cells where you have to enter the IP Address, followed by the website URL and comments(optional). For example, below are a couple of entries made in the Hosts File Editor.
Once you are done making entries, make sure you check the checkbox besides them to make the entry active. If you leave the checkbox unchecked, the particular entry would be commented in the original hosts file making it ineffective. Lastly, click on the Save button to write your changes to the original hosts file.
The best thing about the editor is you can enable and disable the website blocking on the go with a mere click of a button. Traditionally, I would have to delete or comment every entry in the hosts file. But, with the hosts file editor, I just have to click on “Disable Hosts File” and the blocked websites will be available. To enable the hosts file back, click again on the same “Disable Hosts File” option.
When you close the Hosts File Editor, it is minimized rather than closing. So, head over to the bottom tray and quit the application.
2. Import hosts file list
The problem with blocking websites via Hosts file is to you need to manually enter the name of all the websites. Suppose, you want to block adult websites for the entire network. Imagine how gruesome it would be to enter 5000+ website names and IP Addresses in the Host File Editor. The better way to deal with this method is to use an existing Host File over the Internet.
A fabulous example is this GitHub page maintained by Steven Black which is a repository of several hosts file unified. These files serve various purpose from blocking adult content to ads, malware, and fake news. Now, instead of directly copy-pasting the hosts file, a better way would be to use HostsMan, a hosts file manager for Windows.
To start with, install the software. Next, make sure you run it as an Administrator. As soon as the software launches, you will see a button called “Select Sources”. Click on it and HostsMan will display a popup with pre-populated sources.
You can read the description of the pre-populated Host sources, visit their website to verify the contents. But, since we want to add our own custom source, we will have to manually make an entry. To do that, click on the “Add Source” button at the bottom left.
The next page shows blank text boxes for you to enter a suitable Host name, host file URL. After you have entered the URL, click on the “Test connection” button to verify the file. You can find URL, either with a quick Google search or use this URL and scroll down at the bottom of the page to find the ‘Host file recipe’ table.
If you get a message saying “This source seems to be compatible”, you can go ahead and click on OK.
HostsMan also allows you to backup your hosts file prior to an update. It even recognizes changes made by a different tool to the hosts file.
Download HostsMan
3. Multiple Hosts Files
If you use your machine for web development, there are chances that you might need multiple hosts files. For example, you might need a hosts file to redirect a DNS Names to your own IP Address but at the particular instance, you need the URL to be redirected to a remote IP Address. The manual way would be making redundant entries in the hosts file and then commenting out accordingly. But, having multiple hosts files and using a DNS switcher makes the task easier.
You can use a tool called Hosts Switcher. It lets you create multiple hosts file within it and then activate a particular hosts file at a time. This eases the entire process and you can even backup hosts file using the same tool.
Download Hosts Switcher
Update Host File Windows 10
Wrapping Up
All in all, I would really recommend you to use HostsMan over any other Hosts File Editor. For a one-off use case, Hosts File Editor is the ideal option. Another use case would be putting up GitHub hosts file on the router so you can block websites for the entire network. Now, routers don’t have the ability to dynamically update hosts files, so you can setup a Raspberry Pi to do the same job for you. Here’s a Python Script you can run on the Raspberry Pi. It automates the task of fetching hosts file online and updating it on the router.
Adobe Hosts File Windows 10 Youtube
While, Host file is useful but limited. For example, it does not allow for wildcards like DNS. So, you may want to look into DNS blocking using services like OpenDNS.
For any issues or queries, let me know in the comments below.
Also Read: How to Change DNS Server. An In-Depth Guide for All Platforms