Block internet advertising through the terminal for any browser (without using plugins)

Nowadays the Internet has become an extremely popular medium, very dynamic, always on the move ... although several years ago an evil that overwhelmed the network was the excess of animated images (gif) that made reading difficult, and also made it ugly Anywhere, at present we have gotten rid of a good part of the 'fashion' of gifs and in addition to flash files, BUT !, in our network today there is another enemy: Advertising

How many of you access sites in one day from the Internet that have NO advertising?

Let's do a count of popular sites:

  1. Google (has advertising in search results)
  2. Facebook (more advertising could not have)
  3. Twitter (… similar to Facebook, too much advertising)
  4. Sports sites like ESPN, Marca, etc ... the same, too much publicity
  5. And a GREAT etc etc

Nowadays, finding sites that do not have annoying, intrusive advertising (yes, AdSense I'm talking about you!) Is really difficult, the bigger / popular the site is, the more advertising it has, it is almost a constant (with exceptions of course).

The browsers are multiple, we have from Firefox, Chromium / Chrome, Opera, Rekonq, and etc ... if we want to block advertising for all our browsers then we would need to install a plugin that does this in each of them, after the plugin continues to have support for the latest version of the browser, etc.

That is why although Adblock is a very good alternative, I prefer to stick with my method.

Block advertising for all our browsers without installing plugins

The / etc / hosts file serves as a small internal DNS, that is, normally when we access a site in our browser (, for example) the browser asks the world's DNS at what IP address, On what server is that site we want to access, but if we specify the IP in / etc / hosts then there will be no question that the browser should ask.

That is (and getting into the matter):

We must indicate through our / etc / hosts that the advertising domains are on our own PC (, by doing this the browser will search for the advertising on a web server that we have on our computer BUT, as we do not have any web server, then it just won't show anything.

For example, to block Google advertising I run the following in a terminal:

sudo echo "" >> / etc / hosts sudo echo "" >> / etc / hosts sudo echo " googleads.g. ">> / etc / hosts sudo echo" ">> / etc / hosts sudo echo" ">> / etc / hosts

Once this is done, we close the browser and access a site that has Adsense-type advertising, we will no longer see it 🙂

If you use a proxy server then you must add in your browser that the proxy is NOT used for these aforementioned domains, or directly block these domains in the proxy server if it is managed by you

My list of domains in / etc / hosts is somewhat extensive, since there are many sites that offer advertising (as well as unnecessary .js), I frequent sports sites (As, Marca, Central Defense, etc.) in addition to the normal, other types of sites (Twitter specifically I open little, I use Choqok), I leave my list here:

### ADVERTISING ### ad. . 2 vht.tradedoubler. com www.weborama. com 101

This solves almost all of my problems, since I have checked the html of the sites that I frequent to detect the .js or advertising that I do not want my browser to load, hence I took these domains or subdomains to block.

Advantages and disadvantages of this method compared to others like Adblock?

The main disadvantage of this method that I show you with Adblock, is that Adblock is constantly being updated, that is, the plugin already knows which domains it should block, while doing it in this way that I showed you are the ones that should add the domains or subdomains to your / etc / hosts

The main advantage that I see in this method is simple, it works for everyone, absolutely all the browsers that I have or will have on my computer. In addition, I usually use the Alpha versions of Firefox, with this method I avoid that plugins (like Adblock) tell me that they are not compatible with my version of the browser, etc. Oh by the way, I'd rather be the one who blocks the sites, call me crazy but I don't like the idea of ​​a plugin blocking content from my browser, I'd rather be the one who controls this 🙂

Anyway, I know that many might call me selfish because I block advertising (and advertising benefits the authors of those sites), but it happens that my internet connection is really, very very slow, I cannot use bandwidth to load images or advertising that certainly doesn't interest me, which I won't click either.

Here ends the post, I hope it has been useful.


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

46 comments, leave yours

Leave a Comment

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



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   GeoMixtli said

    Hey, getting into the subject a bit and what do you know more about the subject? Isn't there something on the Internet like a list that is constantly updated with all advertising domains? I mean, because if so, I could create a small script that downloads the domain listing and overwrites the / etc / hosts file, and in the process make it run when you upgrade the system.

    PS Thanks, I did not know this trick. It will help me a lot because with Adblock installed, my Firefox takes a precious 7 or 8 seconds to open.

    1.    KZKG ^ Gaara said

      I haven't searched the internet, and yes, the script idea is pretty good 🙂
      If you find a list and need help with the script, let me know, I am glad to collaborate.

      Thank you for reading us.

    2.    Wada said

      Some time ago I found this maybe it will help you 🙂

      More information here:

      They update it often 🙂

      1.    KZKG ^ Gaara said

        Thank you very much for the information, I just read it in another comment.

        Brilliant database, it helps a lot.

      2.    juankfree said

        Here is a tip: The line « # [affects RSS feeds]» gives problems with many RSS feeds, it gave me problems and did not let me access the posts.

    3.    isaac said

      Find the easylist for adblock.

    4.    hey said

      because they do not look at the ad block plus list and copy it, of course it would be necessary to program a little since they use regular expressions

  2.   alunado said

    this good che, it is tedious and the same can be done in windows, but this good.
    Did it happen to you that adblocker (the edge) blocks something of interest?

    1.    KZKG ^ Gaara said

      With plugins for Firefox that block advertising, nothing in particular, but it happens that some sites detect that I have it installed and do not show me a Download button or something similar ... or worse, my navigation slows down with these plugins installed.

      That's why I use this other way to block ads myself 🙂

      1.    Swicher said

        One day I was curious to know if there was something that would prevent this type of detections / blocks against Adblock and after doing some research I came across this curious anti anti blocker (requires Greasemonkey to work) which removes many of the protections used by some sites that force you to disable the ad blocker. I imagine that if this script becomes popular, anti-anti-blockers might well appear to force you to deactivate this script and so on ad infinitum xD.

  3.   Manuel R said

    Although I use AdBlock Edge, it is striking to do it "manually", the only bad thing I see is that it would block advertising from all sites and if there is one where you do not want to block (DuckDuckGo, in my case), I would do it anyway.

    Anyway, I think your method is a very interesting alternative, in case Adblock is not available for X browser. Regards.

    1.    KZKG ^ Gaara said

      Yes indeed, it is all or nothing, there are no exceptions on which site the advertising is displayed on 🙁

      Thanks for reading

  4.   Citux said

    O_o great, I never imagined it could be this way. I block advertising on sites that take forever to load with my connection. Thanks KZKG ^ Gaara 🙂

    1.    KZKG ^ Gaara said

      Thank you

      In fact, very interesting things can be achieved using the / etc / hosts ... I hope I can show it in other articles hehe.

      A pleasure, thanks for the comment

  5.   Sergio E. Duran said

    Excellent contribution friend, it would be better if there was a script that could be installed like any other package in Linux which already had the entire Adblock database that would do all those commands at once so that you don't do it and have it for all browsers, you have a good way to write +1 articles for this

  6.   Leo said

    Let's see what happens. I imagine that it will speed up navigation a lot by not depending on plugins

    1.    KZKG ^ Gaara said

      Exactly, that's why I use it 🙂

  7.   Eduardo said

    A site that I have been looking to update or modify my host file for more than a decade is:
    they update it every few days. You can create a script that automates its download and copy in the / etc / directory

    1.    KZKG ^ Gaara said

      Oh… O_O… very, VERY interesting this database, with this I can program the script so that the process is automatic 😀

      Thank you very much for the information.

    2.    Joaquin said

      Very good, it was what we lacked. Thank you!

  8.   Joaquin said

    Very good article. Especially since the plugins slow down the browser.

    Personally, I am bothered by animated advertising that blocks the entire screen, if it were static on one side of the page, I think nobody would be bothered.

    1.    KZKG ^ Gaara said

      Thank you very much for the comment 😀


  9.   truko22 said

    Great, thank you very much I applied it to my router with tomato, I already removed the doubleclick advertising and now I am testing with the face 😀

  10.   iftux said

    Hello, very good alternative, although I have a little doubt, in my case I have a local web server, do you think this method affects something?

    1.    KZKG ^ Gaara said

      Not at all, the browser will simply search for a VHost on localhost that responds to the domain you declared in / etc / hosts ... if it can't find it, nothing happens, your local server will not affect you /

  11.   Konozidus said

    It's already from a while ago, but here they explain this technique with script using that included db.

    1.    KZKG ^ Gaara said

      I still program my bash script to do it, I like to make my own scripts 😀

  12.   Brian said

    Excellent contribution. I'm having quite a delay in loading with the adblock in firefox so I had to disable it. This is the same as Privoxy does, right?

  13.   roader said

    Qupzilla has built-in AdBlock

  14.   cSB said

    Here I leave a link to a similar article oriented to the arch distribution, and that automates everything necessary using a series of scripts and cronie

  15.   Esteban said

    I do not trust adblockers, to start one of them had an agreement with a company to show advertising to users.

  16.   frameworks said

    With this method or something similar, can an address eg_com be "automatically diverted" to https_porexample_com? is that I still do not know how to enter rules to HTTPS Everywhere 🙁

    1.    KZKG ^ Gaara said

      I didn't understand what you want, can you explain better please?

  17.   eliotime3000 said

    By the next year, I would be exporting that script for Windows and thus sparing many people the problem of adware.

  18.   Talpio said

    Hey, good! The tutorial is excellent. There are no more annoying advertisements on your computer. Thank you Sandman 🙂

  19.   Daniel Gonzalez said


    Simple and elegant solution. Maybe you could have a repo on github, with the entries, plus an update script that adds the missing ones to / etc / hosts so that it is easy to keep it updated.

  20.   Elijah Saadi said

    Hello, I have a question, blocking advertising is not the same as loading your computer with folders and files that there are software to delete because they are unnecessary ???? (cclear and bleach)
    My question is another, if by chance we found a software like privoxy that hides your IP and blocks advertising, how would we do to unassemble that folder that is saving information like the cokies ???

  21.   jhon hemes said

    It is true now on the internet what one finds is advertisements and some inexperienced users are getting into what first aspares them; I used the same method to block the softoni page that brings something that it should not and others that do the same, I placed it so that every time they were to enter it would return it to google

    I personally prefer this one than the "adblock" one.

    and I also thought about the same thing that the colleague «GeoMixtli» said to make a small program or script to keep it updated

  22.   Bertoldo Suarez Perez said

    I feel like Adblock Plus tends more and more to slow down Firefox, and maybe the whole system.
    But, I have concerns with the method of the article. I find it strange, is it just adding the domain of the webpage to the Hosts file, and thus the advertising is blocked ??.
    I have practiced it, but it doesn't, the advertising continues.

    Please, could you explain to me how is the method of , I do not understand precisely. I thought it was backing up the original Hosts elsewhere, and replacing it with the HOSTS extracted from the downloaded Zip.

    Can't you reply to this blog with a wordpress account?

  23.   ZombieAlive said

    KZKG ^ Gaara, what machine do you have, do you use KDE friend. I know you are from CUBA and how they do with many things there.

  24.   Felipe said

    hi, two questions:
    Couldn't that just be done by simply adding that or another list to the blacklist of the firewall (firewall) and already blocking it?
    Your method can be done in the smarphone that has ubuntu?
    Thank you.

  25.   Juanito said

    Thanks for the article. And it could not be called selfishness, since these ads are GARBAGE and nobody needs them, they are exaggeratedly annoying, since for me it is "intrusive" advertising, because by downloading an annoying advertisement, you also download megabytes over the internet and that does more slow your connection.

    Thanks for the tip. 😉

  26.   Pache said

    Hello! my question is very strange, because the situation is so! At some point in my life I downloaded a HOST file already edited for a thousand and one advertisements and… well, it was wonderful !! not even the ads of the videos are activated, it's wonderful.
    Turns out, not only have I done it once, but I recently installed a second operating system and it was wonderful too.

    Now the weird thing: well, exactly the same file, exactly the same process in exactly the same folder and under the same operating system (win7) but on other computers (of my family, etc) it doesn't work!

    Any idea what it could be? Thank you.

  27.   Christian Lenin Morales Rivera said

    I have used this method and it is much better than adblock, I share the internet using the Ubuntu 16.04 hotspot trick, I only made a second list with the hotspot's ip and it worked wonderfully, I will recommend this tutorial to my followers