Domain Name Servers (DNS) bind the internet together. They match machine-usable IPv4 and IPv6 addresses with human-readable domain names. It's the internet's equivalent of the phone book. But, while DNS is utterly essential to the internet, it's not the only way to connect IP addresses with domain names. You can also use Hosts files to connect mysterious IP addresses with meaningful domain names.
A Hosts file is a file that almost all computers and operating systems can use to map a connection between an IP address and domain names.
This file is an ASCII text file. It contains IP addresses separated by a space and then a domain name. Each address gets its own line. For example, 220.127.116.11 is the IP address for CBS Interactive, ZDNet's parent company.
To place this in a Host file you'd enter the following line with a text editor, such as Windows' notepad or Linux's vi.
You never want to use a word processor to create or edit a Hosts file.
To be a valid Host files entry, you can't use website designations such as \, /, or http://. If you put a hash tag, #, at the line's start, you've disabled that entry. The Hosts file will ignore it and move to try find the site via DNS. When an entry is valid, your computer will use the address mapping in the Hosts file and not look it up in DNS.
Why bother when your DNS provider automatically looks up addresses for you? Well there are two main reasons.
First -- and this is minor -- when you go to a site that's in your Hosts file, it will resolve the address a few milliseconds faster than it would if your computer looked it up on DNS.
Using this to speed up your address resolution is too much trouble. If you're always visiting the same sites -- and most of us are -- you'd be better off using the lightweight caching Dnsmasq DNS server. This program automatically saves your DNS queries so that the next time you visit a site, your computer looks it up in the local Dnsmasq cache instead of wasting time going to DNS. This can save as much as 50 percent of your DNS lookup time.
Where Hosts files really shine is by letting you block ads, spyware sites, malware sites, and tracking sites. It does this by blocking your computer from connecting to annoying sites. Specifically, you can list the sites you never want to visit in the Hosts file and give them the loopback address of 127.0.0.1 using IPv4 addressing or ::1 for IPv6 addressing.
What happens then is when a site, email, or what-have-you tries to steer you to a dodgy address, the Hosts file bounces it back and you're kept from going to the questionable domain.
Now you may ask yourself "how do you know which sites to avoid?" Good question, there are thousands of them.
Fortunately, there are three host files ready to go, which include a large list of known ads servers, tracking cookies sites, and other web locations you'll want to avoid. These are: How to make the internet not suck (as much), which despite the name is quite good, hpHosts, and MVPS Hosts. There's also the Hosts File Project, but unlike the others, which are frequently updated, Hosts File Project file hasn't been updated in over a year.
To use any of these, you must first make a backup of your existing Hosts file. On some operating systems you may not have one. I typically rename my existing file hosts.old.
You then create a file named "hosts". You never use an extension with the name, such as hosts.txt, you just use "hosts".
Where you put your new and improved hosts file depends on your operating system and its version. There are several ways to do this. For Windows, MVPS includes an installation routine. With the others, you simply copy and paste their master hosts file to the appropriate destination on your computer.
Before installing a hosts file on a Windows system that's not part of a domain, you must disable the Windows DNS Client Service. To do this, login with an administrative account and click Start, Run and type "services.msc" and click OK. Double click DNS Client service entry, set its startup type to manual and stop the service.
The security program Windows Defender can also get in the way. It can detect changes to the Hosts file as malware activity. To prevent this from happening, you need to tell Defender to ignore the Hosts file. You do this with the following steps:
1. Open Windows Defender.
2. On the Settings tab, click Excluded files and locations.
3. Under File locations, click Browse.
4. Locate and then click the Hosts file. Note By default, the Hosts file is in the %systemroot%\system32\drivers\etc folder.
5. Click Add, and then click Save changes.
6. Exit Windows Defender.
After you've done this, you can install the hosts file in one of the following locations:
For NT, Win2K and XP, use "C:\windows\system32\drivers\etc\hosts" or "C:\winnt\system32\drivers\etc\hosts"
For Windows 7 and Vista, use "C:\windows\system32\drivers\etc\hosts" or "%systemroot%\system32\drivers\etc\hosts"
For Windows 8.x and Windows 10, use "C:\Windows\System32\drivers\etc\hosts"
With Linux or MacOS X, you login as the root user, or use sudo, to move the master hosts file to "/etc/hosts" or on some systems to "/private/etc/hosts". For example, the shell command
sudo cp ~/hosts /etc/hosts"
will move the file "hosts" from your home directory to its home in the etc directory.
Once the host file is in place, you'll see the effects immediately. You don't need to reboot, or, for that matter, reopen your browsers.
You should see a much cleaner and faster internet experience. If you run into problems, revise the hosts file using a text editor if you can see which address is giving you trouble. For example, the how to make the internet not suck (as much) hosts file blocks all Windows 10 reporting domains by default. To fix this you can either delete the offending entry or you can place a # at the beginning of the line and your machine will ignore it.
If all else fails, you can just delete the new hosts file and replace it with the old one. You did make a backup of it right? Right!?
All this will take you a bit of time and effort, but I think you'll find that your increase in speed and privacy and drastic drop in ads will make it worth your time. Enjoy.