The hosts file is a computer file used in an operating system to map hostnames to IP addresses. The hosts file is a plain-text file and is traditionally named hosts. It's like an address book. When you type an address like www.google.com into your browser, the hosts file is consulted to see if you have the IP address, or "telephone number," for that site. If you do, then your computer will "call it" and the site will open. If not, your computer will ask your ISP's (internet service provider) computer for the phone number before it can "call" that site. Most of the time, you do not have addresses in your "address book," because you have not put any there. Therefore, most of the time your computer asks for the IP address from your ISP to find sites. If you put ad server names into your hosts file with your own computer's IP address, your computer will never be able to contact the ad server. It will try to, but it will be simply calling itself and get a "busy signal" of sorts. Your computer will then give up calling the ad server and no ads will be loaded, nor will any tracking take place. Your choices for blocking sites are not just limited to blocking ad servers. In many cases using a well designed hosts file can speed the loading of web pages by not having to wait for these ads, annoying banners, hit counters, etc. to load.
Computers have a host address of their own - it is known as the "localhost" address, with an IP address of 127.0.0.1 which it uses to refer to itself. If you associate another computer's host name with your localhost IP address, you have effectively blocked that host since all attempts to access it will lead back to you.
Severals sites provide hosts files
The hosts file is located in the /etc directory as /etc/hosts.
If there are currently entries in your existing hosts file, then open the ad-blocking hosts file. Copy the text from it to add to the bottom of any existing text in your current hosts file.
Additional links :