The hosts file in Windows is like an address book for your computer. It is loaded into memory (cache) when Windows starts and associates host names, such as www.google.com with IP addresses, such as 220.127.116.11 for Google. The IP address is like the telephone number for that site. However, so we don’t have to remember a string of numbers for every site we want to visit, we enter easy-to-remember host names.
Because the computer uses IP addresses to find sites, it needs to translate the host name for a site into an IP address. If the IP address for a site is in your hosts file associated with a host name, your computer can use that to “call” the site when you enter the host name in your browser’s address bar. If not, your computer must contact a DNS (domain name server) computer on the Internet for the IP address before it can contact the site.
Initially, there are no host name/IP address associations in the hosts file. Examples of the format and layout of the IP addresses and host names are listed in the comments in the file.
If you add host names and their associated IP addresses into the hosts file for sites you visit often, access to those sites becomes faster. Your computer doesn’t have to query DNS servers on the Internet to get the IP addresses for those sites. If there are any sites that don’t have a domain name, you can enter the site’s IP address in your hosts file with a custom domain name which can serve as a “shortcut” to the site.
So how can you use a HOSTS file in Windows? Well, websites can collect various types of information about you as you surf the web. The hosts file can help block sites from tracking you, as well as block ads, banners, third-party cookies, and other annoying parts of web pages.
Each computer has a host address of its own, known as the “localhost” address. The IP address for localhost is 127.0.0.1. This can be used to block sites serving ads or objectionable content by entering a site’s host name in the hosts file and associating it with the localhost IP address. That refers the host name to your own computer, which then thinks it found the site and displayed it already, even though that site was never actually contacted.