How to block ads on any web browser on Linux

Last updated on March 28, 2013 by Dan Nanni

If you want to block ads while surfing the web on a web browser, there are browser-specific plugins to use (e.g., AdBlock or Adblock Plus on Chrome and Firefox). But if you are looking for a browser-agnostic or plugin-free way to remove ads from web pages (i.e., block ads on any web browser), this guide can help you.

A simple way to block ads on any web browser is to set up a local http proxy which then filters advertisements embedded in web pages, and renders ads-free web pages for you. One such proxy is Privoxy which is equipped with advanced filtering capabilities that can filter a wide range of well-known ads from web pages.

Install Privoxy on Linux

For Ubuntu or Debian:

To install and start Privoxy on Ubuntu or Debian, run the following.

$ sudo apt-get install privoxy
$ sudo /etc/init.d/privoxy start

For Fedora:

To install and start Privoxy on Fedora, use these commands.

$ sudo yum install privoxy
$ sudo service privoxy start

For CentOS or RHEL:

To install and start Privoxy on CentOS or RHEL, first set up EPEL repository on your system, and then run the following.

$ sudo yum install privoxy
$ sudo service privoxy start

Configure Privoxy

After installation, you can check whether Privoxy is running successfully as follows.

$ sudo netstat -nap|grep privoxy
tcp        0      0 127.0.0.1:8118              0.0.0.0:*                   LISTEN      2093/privoxy

Now, edit proxy setting for your web browser as follows.

Once proxy setting has been edited, you can browse web sites as usual. You will find that websites are now free of ads. For example:

New York Times website before enabling Privoxy:

New York Times website after enabling Privoxy:

You can customize Privoxy's default filtering rules by editing /etc/privoxy/default.action.

$ sudo vi /etc/privoxy/default.action
. . . .
#----------------------------------------------------------------------------
# JavaScripts and Texts for ad and popup generation
#----------------------------------------------------------------------------
# Blocked URL = http://pagead.googlesyndication.example.com/foo/bar/baz.js
pagead*.googlesyndication./.*.js
# Blocked URL = http://a.tfag.de/js.ng/
/js.ng/
/popunder
/js/slider.js
/t.php?cat=.*&kw=.*&sc=
scripts.chitika.net/.*.js
jlinks.industrybrains.com/
.adinterax.com/.*.js
.googleadservices.com/gampad/.*.js
js.adsonar.
. . . .

After filtering rules are updated, make sure to restart Privoxy.

On Ubuntu or Debian:

$ sudo /etc/init.d/privoxy restart

On CentOS, RHEL or Fedora:

$ sudo service privoxy restart

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean