The hosts in Windows is a special file that holds the domain name to IP address resolutions. Whenever we connect to a website, that application may first check the hosts file for domain name entry and related IP address. If no such entry is found then that application connects to a DNS server for domain name resolution.
We can manually edit hosts file using Windows Notepad, Notepad++ or any text editor that saves data in plain text. But there are many helpful tools that can make editing hosts file easy. For example, there is an open-source tool called hostsmgr (Hosts Manager) using which we can automatically update the hosts file. This tool can download the ready-made hosts files from various online sources and merge the entries with the local hosts file.
Before using this tool, we have to carefully examine the entries of three files – hosts_sources.dat, hosts_userlist.dat and hosts_whitelist.dat. It consults these files for updating your local hosts file. These files can be found in the same folder as the hostsmgr.exe program file.
The entries in the hosts_sources.dat are all online resources for the hosts file. These entries will block many unwanted, malicious domains through the hosts file. It includes too many of these resources so you should carefully remove the ones that you do not want. For ordinary users, a single resource from http://winhelp2002.mvps.org/hosts.txt is more than enough. Entries in the hosts_userlist.dat are user defined domain names list that is blocked. Similarly entries in the hosts_whitelist.dat are allowed.
Once this is done, you can invoke hostsmgr using a simple command line this: hostsmgr.exe” -ip 0.0.0.0 -os win -path “.\hosts” which would generate a file hosts in the same folder as hostsmgr.exe containing all the updated entries. Later you can examine this hosts file and copy it yourself in the C:\Windows\System32\drivers\etc. However, if you specify only a single parameter such as -ip 127.0.0.1 then it will set all other parameters to the default value and directly updates your system hosts file.
It is a really useful hosts automatic update utility for Windows users. We can set it into a batch file for automatic execution at scheduled times to keep the hosts file updated.
You can download hostsmgr from https://www.henrypp.org/product/hostsmgr or from its GitHub page at https://github.com/henrypp/hostsmgr.