How to block ads on any web browser on Linux

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.

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

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

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

$ sudo yum install privoxy
$ sudo service privoxy start

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

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

$ sudo netstat -nap|grep privoxy
tcp        0      0    *                   LISTEN      2093/privoxy

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

  • Proxy host:
  • Port: 8118

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 =
# Blocked URL =
. . . .

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

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

11 thoughts on “How to block ads on any web browser on Linux

  1. I run a Linux based router called smoothwall. I have a plug in for smallwall called AdZap that removes ads for anyone on my network. Nothing is needed on the client side, since the router is stripping the ads.

    • That’s so much more difficult for the average user than simply installing a browser plugin. Plus, the filters for those plugins are automatically updated. I’ve used privoxy before, and this sort of application of it might be useful on a server or something, but… no.

      • quite possibly. I'm not touting that smoothwall is the way to go (or eve the best option). The concept/architecture is the important bit.

  2. I like Adblock Plus, it works for me and I trust it (for the moment). But this alternative looks good.

  3. One of the big advantages of something like adblock is I can disable it easily for specific items or pages.

  4. Well this is useful in my small company where I can set this up on my Linux firewall/gateway and filter ads for 10-12 people.

  5. I use a combination of router-based ad blocking (fabulous for those painful mobile apps with ads) and AdBlock for the sneakier JavaScript ads.

  6. There's a far simpler way to block ads than to go through installing new software and configuring the browser to use a proxy.

    is a list of known ad services, including popup windows and the like and it aliases the names to, which isn't running a web server, so you don't even waste time connecting to those sites. Some later versions of Linux (Ubuntu) get upset with using, so you can change it to So download it using

    wget -O - |sed 's/' > hosts

    Then "install" using

    sudo bash -c 'cat hosts >> /etc/hosts'

  7. I don't use plugins or router blocking. I just tell my nameserver that it is authorative for and a few other domains and give apache a few rules for them. As a result no machine that gets a dhcp address from me can see any ads. Its a nice setup.

Leave a comment

Your email address will not be published. Required fields are marked *