Hostsfile
A hostsfile contains the mappings of IP addresses to hostnames. This file is loaded into memory (cache) at startup, then the operating system checks the hostsfile before it queries any dns servers, which enables it to override addresses in the dns.
How it works
This method prevents access to the listed sites by redirecting any connection attempts back to the local machine. Another feature of the hostsfile is its ability to block other applications from connecting to the Internet, providing the entry exists.
You can use a hostsfile file to block ads, banners, 3rd party cookies, 3rd party page counters, web bugs, and even most hijackers. This is accomplished by blocking the connection(s) that supplies these little gems.
Examples
The following entry 127.0.0.1 ad.doubleclick.net blocks all files supplied by that DoubleClick server to the web page you are viewing. This also prevents the server from tracking your movements. Why? … because in certain cases “Ad Servers” like Doubleclick (and many others) will try to open a separate connection on the webpage you are viewing.
Windows
'If you are a windows user: HostsMan is a freeware application that lets you manage your hostsfile. Includes an option to turn off the unneeded DNS client service. This also has an option to update the existing HOSTS file when needed and allowing to add your own hosts file remote update list.
Hosts for unix/linux
Updated: 13/08/2019 with 1.800.000 addresses