How to Use a Hosts File to Improve Your Internet Experience

Domain name servers (DNS) tying the internet together. They combine machine-usable IPv4 and IPv6 addresses with human-readable domain names. It is the Internet equivalent of the telephone directory. But, although DNS is absolutely essential to the Internet, it is not the only way to connect IP addresses to domain names. You can also use Hosts files to connect mysterious IP addresses to 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 then a domain name. Each address gets its own line. For example, is the IP address of CBS Interactive, the parent company of ZDNet.

To put this in a Host file, you must enter the following line with a text editor, such as Windows Notepad or Linux vi.

You never want to use a word processor to create or modify a Hosts file.

To be a valid host files entry, you cannot use website designations such as , /, or http://. If you put a hash tag, #, at the beginning of the line, you have disabled that entry. The Hosts file will ignore it and try to find the site via DNS. When an entry is valid, your computer uses the address mapping in the Hosts file and does 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 is in your Hosts file, the address will be resolved a few milliseconds faster than if your computer was looking it up on DNS.

Using it to speed up your address resolution is too complicated. If you always visit the same sites – and most of us are – you better use lightweight caching Dnsmasq DNS server. This program automatically saves your DNS queries so that the next time you visit a site, your computer looks for it in the local Dnsmasq cache instead of wasting time going to DNS. This can save you up to 50% of your DNS lookup time.

Where Hosts files really shine is in allowing you to block ads, spyware sites, malware sites, and tracking sites. It does this by preventing your computer from connecting to annoying sites. Specifically, you can list sites you never want to visit in the Hosts file and assign them the loopback address using IPv4 addressing or ::1 for IPv6 addressing.

What happens then is when a site, email, or whatever tries to direct you to a dodgy address, the Hosts file returns it and blocks you from accessing the dodgy domain.

Now you may be wondering “how do you know which sites to avoid?” Good question, there are thousands.

Fortunately, there are three ready-to-use hosts files, which include a large list of known ad servers, tracking cookie sites, and other web locations you’ll want to avoid. These are: How to make sure the internet doesn’t suck (as much), which despite its name is quite good, hpHosts, and MVPS Hosts. There is also the Hosts file project, but unlike the others, which are frequently updated, the Hosts File Project file has not been updated for over a year.

To use any of them, you must first make a backup of your existing Hosts file. On some operating systems, you may not have one. I usually rename my existing file hosts.old.

You then create a file named “hosts”. You never use an extension with the name, like hosts.txt, you just use “hosts”.

The location of your new 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 just need to copy and paste their master hosts file to the appropriate destination on your computer.

Before installing a hosts file on a Windows system that is not part of a domain, you must disable the Windows DNS Client Service. To do this, log in with an administrator 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 Windows Defender security program can also get in the way. It can detect changes to the Hosts file as malicious activity. To prevent this from happening, you need to tell Defender to ignore the Hosts file. For that, proceed as following :

1. Open Windows Defender.

2. On the Settings tab, click Excluded files and locations.

3. Under File locations, Click on Browse.

4. Locate and click on the Hosts file. Note By default, the Hosts file is located in the %systemroot%system32driversetc folder.

5. Click To add, then click Save changes.

6. Quit Windows Defender.

After that, you can install the hosts file in one of the following locations:

For NT, Win2K and XP use “C:windowssystem32driversetchosts” or “C:winntsystem32driversetchosts”

For Windows 7 and Vista, use “C:windowssystem32driversetchosts” or “%systemroot%system32driversetchosts”

For Windows 8.x and Windows 10, use “C:WindowsSystem32driversetchosts”

With Linux or MacOS X, you log in 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 “hosts” file from your home directory to its home directory in the etc directory.

Once the host file is in place, you will see the effects immediately. You don’t need to restart or, for that matter, reopen your browsers.

You should see a much cleaner and faster internet experience. If you’re having trouble, review the hosts file using a text editor so you can see which address is giving you trouble. For example, the hosts file how to make the internet not zero (as much) blocks all Windows 10 reporting domains by default. To fix this you can either remove the offending entry or put a # at the beginning of the line and your machine will ignore it.

If all else fails, you can simply delete the new hosts file and replace it with the old one. Did you make a backup of it? To the right!?

All of this will take you a little time and effort, but I think you’ll find that your increased speed and privacy and the drastic drop in ads are worth it. Enjoy.

Related stories: