Block internet advertisements with your hosts file
Use your computer’s ‘hosts’ file to make sure you never see advertisements on the internet again.
A lot of individuals consider internet advertisements to be a major annoyance because:
- They are often flashy and distract from a site’s main content.
- They slow the loading of websites and increase your downloads.
- Some internet advertisers distribute adware/spyware within their advertisements.
One of the easiest ways to prevent advertisements from displaying on the websites is via the hosts file that resides on your computer.
The hosts file is a plain-text file located at
c:\system32\drivers\etc\hosts on computers running Windows XP, Windows Vista and Windows 7. Location information for the hosts file on Mac systems can be found here.
The purpose of the hosts file is to map domain names (for example: adonline.id.au) to an IP address (for example: 22.214.171.124) so that your computer can access those websites. In the early days of the internet, people would maintain lists of websites but these days we have the Domain Name System (DNS) to fulfil this purpose. Essentially the hosts file is a relic from past times.
The hosts file can be opened via a plain-text editor such as Notepad. You will see that the file has no extension.
Whenever you attempt to connect to a website, your computer will consult your hosts file before the DNS in order to resolve the web address. It is this function that can be used to block ad servers and malicious websites.
In simplified terms, your computer will identify itself as
localhost and consider its hard drive to have the IP address of
127.0.0.1, regardless of what IP your internet service provider or network has assigned to your machine.
You can modify the hosts file so that ad server domains also map to 127.0.0.1 instead of their proper locations. This tricks your browser (or other applications) into believing that the ads are locally-served, which they are not. Because the advertisements can’t be located properly, they won’t be displayed on the websites that you visit. This leaves you with ‘clean’-looking websites devoid of most advertising. A hosts file can also be used to block other malicious sites, too.
How to block advertisements with your hosts file
Clearly, compiling a master list of ad servers is a big job. Fortunately, several websites offer ‘ready-made’ hosts file that can be downloaded. The most popular one is supplied by MVPS.org and is updated regularly by a large team of contributors.
The MVPS hosts file can be downloaded as a plain-text .txt document via the following link:
I suggest that hosts.txt be saved to the desktop.
To use this file, use Windows Explorer to navigate to C:\Windows\System32\drivers\etc on your computer. Right-click on your hosts file and choose the “rename” option. Rename your existing hosts file to “hosts-old”. You will require administrator’s privileges to do this.
Arranging your Windows Explorer window so that you can see the hosts.txt file icon, drag hosts.txt from the Desktop to
C:\Windows\System32\drivers\etc in your Windows Explorer window.
Right-click on hosts.txt and choose the “rename” option. Rename the file to “hosts” (without the .txt extension).
Your new hosts file is ready for use. Note: You may need to clear your browser cache before it completely takes effect.
Altering your hosts file:
Sometimes you may want to manually add entries (or delete them) from your hosts file.
To manually add entries into your hosts file, simply open the file in Notepad or another plain-text editor such as Programmers Notepad or Notepad++. Do not open your hosts file in Word or another word processor.
Ad server entries (or any other website you wish to block) are listed in the following format:
127.0.0.1 au.a1.yimg.com 127.0.0.1 richmedia.yimg.com 127.0.0.1 ts.richmedia.yahoo.com
In this example, the adservers
ts.richmedia.yahoo.com are being blocked. In essence, every domain that you wish to block is prefaced with “127.0.0.1” in a long list with one domain per line.
Insert additional lines by typing “127.0.0.1” then a space, then the name of the server that you wish to block. Do not add “www”.
When your list is complete, save your hosts file and close Notepad. You may need to clear the cache on your browser in order for the blocks to take effect.
Now when you surf the web, you can do so free of annoying advertisements. You should also find that instant messaging programmes such as Yahoo Messenger are also now free of advertisements.
You may wish to update your hosts file every few months, as new ad servers are launched around the world.