How to disable Ads using HOSTS file in Microsoft Windows/Linux/UNIX
One way of avoiding online advertisements is to redirect all requests to Ad sites to locahost so that bandwidth is well utilized. It also results in faster browsing as it eliminates Domain Name Service (DNS) requests. For this you need to define custom entries for Ad servers in system HOSTS file to redirect them to localhost (127.0.0.1). The browser first looks at the system HOSTS file for known hosts and if it doesn’t fin it there it will contact the DNS server to resolve IP address of the host name.
The Location of HOSTS file in various operating systems:
The HOSTS file is present in “%WinDir%“. If you have windows installed in C: drive, typically the location would be “c:windows“.
The HOSTS file is typically present in “%SystemRoot%\system32\drivers\etc” directory. However the actual directory is determined by “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath” registry key.
Linux/UNIX-like operating systems:
The hosts file is present in /etc directory as “/etc/hosts” file. Please note that all letters are in lower case as the case matters in UNIX-like operating systems.
BSD/Mac OS X/iPhone/iPod:
The hosts file is “/private/etc/hosts“.
All entries in HOSTS file start with an Internet Protocol (IP) address followed by host name. For example all HOSTS files in all operating systems will have the following entry by default.
Now to disable on-line Ads, you would need to add entries like the above to redirect all Ad server pages to localhost.
For example the following entry added to system HOSTS file causes Ads from DoubleClick.net,
This method requires adding all on-line Ad server host names to be added to system HOSTS file.