Block ads, tracking and more

If you want to block any or all of ads, tracking, fake news, gambling, pr0n, social websites, you might be tempted to install some software or a browser extension. It may work well, but if you're like me and want to do more with less, then there's a way to quickly hack it yourself.

I have recently come across this awesome repository. They keep up to date and unify a list of dodgy domains in host files, and you can download one and replace or append it to your host file. It will "block" the domains that you don't want your computer connect to.

To keep the list automatically up to date on your computer, you can schedule a job with cron. On OSX or Linux, open a terminal and run the following commands:

# keep your original settings

sudo cp /etc/hosts /etc/hosts.custom

# edit cron with vim, change with nano for example, if you prefer

EDITOR=vim sudo crontab -e

# add this line (you might want to use a different hosts list here)
30 10 * * * cd /etc && cp hosts.custom hosts && curl >> hosts


This will update the list every day at 10:30am. Any other changes that you want to make to the host file should be done in the hosts.custom instead.