Have you ever wondered about the role of the Windows Hosts file on your computer? It’s a simple text file that can override IP addresses, helping you block domains or access development websites. Imagine the possibilities – from improved privacy to efficient web development. Get familiar with your Hosts file and experience its benefits.
Another way to think of the hosts file is as an address translator and redirector. If you went to New York City and asked to go to the New York Times Company, someone would translate your request into 229 West 43rd Street. A similar process happens on the web. Your web browser first checks your hosts file to see if it has any IP addresses for nytimes.com. If your hosts file has an entry, it is used. Otherwise, a domain name server is queried to get the IP address.
The Benefit of Hosts File
One benefit of using the hosts file is precedence. Most operating systems access this file first because it’s loaded into the computer’s memory at startup. There are some exceptions, such as people who use proxy servers.
When various Internet advertisements became invasive, some people used the hosts file to bypass the ad servers. People would add an entry to their hosts file that redirected an ad server away from the intended destination. Today, people use ad blockers.
And while the file has benefits, it can also be abused. Malware or hackers could use the same logic to redirect a domain to one of their choosing. For example, they might redirect your bank’s web to a fake domain that looks like your bank’s site. Perhaps the only difference is that the URL looks slightly different under scrutiny.
Hosts File Example
A more common use these days is for local web development. For example, I have a local instance of this website on my PC for testing. To display the website in my browser, I would add a line to my hosts file like the one below.
When I type the test domain name, www.timeatlas.local, into my web browser, the system first looks in the hosts file and finds the entry 127.0.0.1. This IP address is a universal address assigned to your PC’s local host. So, rather than going out to the web, the request would stop at my PC. In this case, timeatlas.local doesn’t exist on the internet.
Hosts File Location
The good news is you control the hosts file provided you have admin access to your PC. You can add, edit, or delete entries using a text editor. However, there may be security issues that deny you access. Microsoft support has provided a knowledge base article on modifying the hosts or lmhosts file.
It’s probably worth 5 minutes to review the file if you ever need to edit the hosts file. The hardest part is probably finding the file, and it is not just limited to the Windows operating system. Each operating system (OS) locates the file a bit differently.
- Microsoft Windows:
- Mac OS X:
How to Use Hosts File to Block Domains
You might want to modify your hosts file for other reasons besides local development. For example, if you don’t want people to access sites and don’t have a router or software that blocks domains.
For example, if I wanted to block access to Amazon, I could add this line to my Hosts file.
127.0.0.1 www.amazon.com #Block Amazon
In this instance, I’m telling the computer to assign the IP address 127.0.0.1 for Amazon. The # sign represents a comment line.
If someone uses that computer and types www.amazon.com in the address bar, they would get an error message. The text varies based on which browser you use.
Plenty of articles and resources exist if you want to find more host files. Some people have compiled lists that you can download. Others have programs that make editing the file easier. I find many of these lists are cumbersome to maintain, and don’t use them. And if you do decide to change your hosts file, please remember to make a backup first.
Troubleshooting Windows Host File
Sometimes after making changes to the file, you get unexpected results. For example, I got the site instead of getting blocked when I typed the Amazon URL. Here are some common reasons.
- You are using a proxy, and it may be taking precedence. You can find this out by going to your Network & Internet settings.
- You need to clear your DNS cache. Go to your Windows Command and type ipconfig / flushdns
- You have a # symbol at the beginning of the line.
- The file won’t save because you don’t have Admin permissions. Try running your editor app as an Administrator.
- You made a typo when adding the line such as omitting the space between the IP address and domain.
- You saved the file in a different format. It needs to be a text file with no file extension.