The hosts file is a hidden file in all internet connected computers that redirects domain names to their correct
IP address without the
domain names system. Most computer users never see or use this file in any meaningful way. However, it can be an extremely powerful tool for combating malicious websites and ads. You can use the hosts file to block certain websites from connecting to your computer (and vice-versa) by redirecting their domain names to your
localhost (127.0.0.1). Are you still with me?
A good man named
Dan Pollock has compiled an extensive list of ad servers and malware sites and put them into a custom hosts file that you can use! By adding this list to your hosts file, you can block almost every online ad imaginable, its even more effective than
Ad Block Plus.
First things first, you need to get to your hosts file. You must have administrator privileges to access it.
On Windows, the hosts file is located at:
C:\windows\system32\drivers\etc\hosts
Open the file in Notepad.
On Mac OS X, it's a little more complicated.
It is located at:
Macintosh HD/private/etc/hosts
but the
/private folder is hidden. To view it, enter Terminal (in the Utilities folder) and type:
defaults write com.apple.Finder AppleShowAllFiles YES
Then type:
killall Finder
And hit Enter, the Finder will restart and you should see a faded folder named
private. Navigate to the hosts file and open it in TextEdit.
To hide the folders again type:
defaults write com.apple.Finder AppleShowAllFiles NO
Then do
killall Finder again.
If you are using Linux then you should already know where to find it.
First thing you want to do is create a backup of your hosts file before you modify it. Save it as
hostsbackup.txt and put it somewhere you won't lose it.
Now, copy and paste
this (yes, all of it) into the hosts file a line below the text already in it. The file has more detailed instructions if I am not clear enough.
The link above is just a basic list of ad sites. Alternatively, you can use
this or
this hosts file instead (which are much larger and block even more ads), or combine all three into one.
Finally, you may want to scan through it for websites you don't want blocked for whatever reason (use ctrl+f to search).
If you want to add a site to the list that you want to block, on a new line type:
127.0.0.1 the website.com (do not include the http:// or www.)
Save the file as
hosts without an extension (no .txt) and replace the original hosts file when prompted.
Your internet just got better!
If you are experiencing problems, just replace it with your backup copy of the original. (Be sure to save it in the correct folder and with no file extension)
You can use this trick to pull pranks as well. The hosts file can be used to forcibly redirect one site to another. If your friend or co-worker has administrator access and is stupid enough not to lock his computer when unattended, you can go to the hosts file and add a line. First, type the IP address of the site you want them to be redirected to. (
Use this tool to find IP's) Then put a space and then type the website you want to trigger the redirect. Here is an example entry:
69.65.107.209 google.com
Now, whenever he tries to go to google.com, he will be redirected to the infamous
lemonparty.org !
To reverse it, simply delete the entry you added from the hosts file.
UPDATE: One of the secondary hosts files I provided (the one from hosts-file.net) is breaking the entire hosts file on my Mac. If you are a Mac user, do not use the file from that link or part of it.