What is host file?

The  answer is that the Hosts file is like an address book. When you type an address like www.yahoo.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. You may block sites that serve advertisements, sites that serve objectionable content, or any other site that you choose to block.

To configure the  Host file in Mac os X.
1. Open terminal (Type terminal in spotlight).
2. Then type “sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts
3. Then enter the password  for root account.(Password will not be shown).
4.  Text edit will open up with loading Host file.
5. Add any server ip address and domain name.
6. save the file.

On Leopard you can issue a simple Terminal command to flush the DNS cache, and have your host file changes to take immediate effect:

 dscacheutil -flushcache