etc/hosts and ad Blocking

Posted in software by Christopher R. Wirz on Thu Feb 28 2013

The internet host table specification has been available since 1985. It is available in all operating systems. It basically works like a Domain Name System (DNS) but is not automatically published.

In Windows, when running as admin, it can be accessed as follows:

notepad.exe C:\Windows\System32\drivers\etc\hosts


notepad.exe %SystemRoot%\System32\drivers\etc\hosts

And in ubuntu 18.04 (and OS X)

sudo vi /etc/hosts

Now let's look at the format. It firsts lists the ip address, then the host name(s). Blank lines are ignored, as are the contents following a # in a line.  localhost loopback
::1        localhost

The trick to ad-blocking is to take the host name for an ad service and direct it to the localhost. This can be done as follows:

All you have to do is save the etc/hosts file, and that's it. No application install required. This trick can also be used to use a hostname for private development or staging servers that are listening to be addressed as a specific host name.

Looking for a job?