hosty: Script to remove ads in any browser

Since I tried the AdAway app for Android I looked for the same thing for Linux, but I couldn't find it, if there are similar solutions like the one already published here Script to remove advertising in any browser, but it's not exactly what I'm looking for. What is the difference? AdAway takes multiple fonts, merges them, removes duplicate lines, and cleans up the file.

And also the scripts that it found did not use your original hosts file, that is, the configurations of your hosts file were not in the generated hosts file. So searching I found a script that came very close, I edited and changed it to finally achieve exactly what I wanted, the result of this is guests, so call it.

Advantages over AdBlock and other browser extensions? In addition to the fact that this works on the entire operating system at once, it avoids the use of resources of this type of extensions.

Requirements:

Requires cURL and Wget

We install the requirements:

Ubuntu / Mint / Debian:
$ sudo apt-get install curl wget

Arch / Manjaro / Antergos:
$ sudo pacman -S curl wget

Fedora / RHEL / CentOS:
$ sudo yum install curl wget

SUSE:
$ sudo zypper in curl wget

Install hosty:

$ sudo rm /usr/local/bin/hosty ; sudo wget -c https://github.com/juankfree/hosty/raw/master/hosty -O /usr/local/bin/hosty ; sudo chmod +x /usr/local/bin/hosty

Now we run it (Remember to run it at least 1 time per week or per month to have your hosts file updated and to block new advertising sites):
$ hosty

Restore original hosts file

$ sudo cp /etc/hosts.original /etc/hosts

Uninstall the script

$ sudo rm /usr/local/bin/hosty

Tip: If you want to modify the hosts file, I recommend that you modify the /etc/hosts.original file and then run hosty, in this way hosty will generate the hosts file with your personal settings (Do this if you have already run hosty, not before.).

All the script code available in my GitHub.

Regards!


59 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.   Jorge said

    Don't forget to add it to the Cron, too. I did it to make that hit for me.

    I just tested it, and it works perfectly. I would even go so far as to say that it works better than the method with daemons like Squid or Privoxy.

    It is appreciated!

    1.    Jorge said

      A doubt, yes:

      How do I contribute to my list of blocked ads? I'll upload some to my github that I just tried and they work.

      The drama is also that the space (section) is left with a space with a warning that "it cannot be connected." Help is appreciated 😀

      1.    johnfree said

        I got the issue, it was already included, run hosty to update the hosts. They are taken directly from your repository.

  2.   babel said

    Wonderful method. Simple and easy. Thank you.

  3.   Chaparral said

    Thanks for the input. Works.

  4.   ThecaTony said

    Thank you very much for your work, I will try it.

  5.   Joaquin said

    Good post! I think you misspelled a command if I'm not mistaken:

    sudo cp /etc/hosts.original / etc / hosts

    Shouldn't it be the other way around?

    sudo cp /etc/hosts /etc/hosts.original

    1.    johnfree said

      No, this well written is to restore the original file. The only steps required are to install and run, the others are to go back to the original host and to uninstall the program.

      1.    Joaquin said

        Yes, it is that I had not seen the code of your script. Now I understand that the script makes a copy of the original called "hosts.original" and I screwed you up. I thought it was to make the copy before running the script. Cheers!

  6.   soymicmic said

    Very good, I really like it.

    The only suggestion I see is at the point "Parsing, cleaning, de-duplicating, sorting ..." include there a "white list" file or exceptions

    1.    johnfree said

      Ready, from now on you can include exceptions in /etc/hosts.whitelist one per line. It can be the address alone or with 0.0.0.0 or with 127.0.0.1 at the beginning.

  7.   ianpocks said

    It works super well at least for now !!!

    Thank you so much 🙂

  8.   Bert said

    Great. Just what I needed. In Kontact it was impossible to open the browser without the string of ads hanging from the article to read.
    Thank you.

  9.   Xurxo said

    Thanks for posting the script.
    It is easily auditable, editable and saves me from having to update my list in / etc / hosts every so often.

  10.   rawBasic said

    Very good. Thanks for sharing. Argentine greetings.

  11.   Martin said

    One question, is this method detectable by anti-adblock websites that swarm the web?

    1.    johnfree said

      If it is detectable, so far on only one website I had this problem.

      1.    johnfree said

        Fix it by adding the web to the whitelist.

      2.    Martin said

        Thanks for the answer and for the tool.

  12.   xpt said

    Very good !!
    Thank you!!

  13.   pegasusonline said

    How good this script is!

    As a suggestion I would tell you to improve the implementation and massification of the script is that in the instructions, use git clone / git pull so we all benefit from the updates!

    Thank you very much and keep it up!!!

    regards
    PegasusOnline

    1.    johnfree said

      I don't use git for this but the script ALWAYS runs automatically updated from day 0. With this simple line it always runs updated.
      https://github.com/juankfree/hosty/blob/master/hosty

      Regards!

  14.   moa said

    At what point would you restore the original host file? Or I don't have to restore it because that step I did not do, as I add it to the cron, and also how would I modify the original hosts, how it goes 😀

    1.    Juank said

      Exactly, restoring the original host obviously doesn't have to be done.

      Regarding cron, I don't use it with cron, Google surely has very good tutorials, it is in my plans to extend hosty, graphical interface, cron, etc. but in the future.

      To modify hosts.original:
      In a terminal: $ sudo FAVORITE-TEXT-EDITOR /etc/hosts.original

      Regards!

  15.   cyttorak said

    Hello

    I have tried to improve your script and have left it like this: https://github.com/cyttorak/hosty/blob/master/hosty.sh
    What do you think?
    This is my first time forking on github so please let me know if I should have renamed the script to respect your authorship or add some recognition or just like this.
    Thank you.

    1.    Juank said

      Hola!
      I'll explain how to proceed normally in Github when you want to contribute to a project 🙂
      1) Fork - Done
      2) Modify what you want, maintaining compatibility with the original project - Half, you modified things that do not correspond in hosty original, I think you understand what I mean, and please keep all the texts in English.
      3) Make a pull request to the original project, to do this you must go to your repository, go to Pull Requests https://i.imgur.com/Y1PMKST.png then to New pull request http://i.imgur.com/ljhaIdH.png and explain all the changes made
      4) Then I accept the pull and voila, the original hosty is updated with your username as the author.

      Thank you very much for your interest, if you want to contact me quickly on my blog you have my social networks http://juankblog.tk/ preferably on Twitter, or G + if you don't have one. Cheers!

      1.    cyttorak said

        Hello
        I have already modified the message that I have in Spanish.
        About point 2 of compatibility, I don't know what you mean, is it because of the use of awk?
        Probably to be out all day, so tomorrow I'll do the pull
        Thanks a lot. Bye.

    2.    Juank said

      I mean changes to README.md, hosty and install.sh, they are not supported by the project. Go back to the original files.

    3.    Juank said

      Ready, adapt the readme and the aur package to the new code and made them more readable.

      Greetings and thanks for your collaboration with the project, long live free software! : D.

      1.    cyttorak said

        One question, why are the domains on line 42 of https://github.com/juankfree/hosty/blob/master/hosty.sh through thirst? Doesn't that mean a whitelist regardless of what the user does?

    4.    Juank said

      Hosty is an ad blocker, I thought so, if it blocks websites in such a way that it is impossible to access the content, it becomes a self-imposed censorship and moves away from being an ad blocker, even if more ads are shown, at least this I can access the websites, since the idea is to be able to use all the websites, even if it means seeing advertising.

      Sed is used because ... I don't know, it worked at the time I wrote it simply, the idea would be to use the same method as the whitelist file, and for the user to decide with the -a / –all parameter if he wants to block everything or not, although I think you can't take parameters unmodified https://github.com/juankfree/hosty/blob/master/hosty or if?

      1.    cyttorak said

        I have done the test and if I could.
        Mira http://back.host22.com/ej.sh
        and run
        bash <(curl -s http://back.host22.com/ej.sh) one two three four
        the output will be:
        Param: one
        Param: two
        Param: three
        Param: four

        In a while I'll do another pull with some improvements

      2.    cyttorak said

        I have done the test and if I could. Run
        bash <(curl -s back.host22.com/ej.sh) one two three four
        and the output will be:
        Param: one
        Param: two
        Param: three
        Param: four

        In a while I'll do another pull with some improvements

      3.    cyttorak said

        I have done the test and if I could. Run
        bash <(curl -s back. host22. com / ex.sh) one two three four #remove the spaces from the url, I write it like this because otherwise the comment will not be published
        and the output will be:
        Param: one
        Param: two
        Param: three
        Param: four

        In a while I'll do another pull with some improvements

  16.   snack said

    I suppose it would be too much to ask that the advertising window disappear like adblock does? 😛 to ask that it not remain. For the rest, the script is fabulous and you can see the consumption of ram and more with 20 tabs open. Can I add more lists?

    1.    yukiteru said

      It is not difficult, you can use a custom CSS style in Firefox to prevent those windows from remaining, there is information about the procedure here, http://foro.desdelinux.net/viewtopic.php?pid=22259#p22259

      The method is essentially the same, only one more step is added to avoid the ugly page that appears saying that the web page is not available. I hope it helps.

  17.   Patrick said

    Thank you very much, it is what I was looking for for Spotify, will it be possible to hide the advertising box of the Linux client? Do I need to add it to Cron?

    Regards,

    1.    Juank said

      You're welcome 🙂
      I do not know, but it is part of the app itself, I do not think it is very easy
      No, I always update manually
      Greetings: D!

      1.    lesco said

        I have it installed from AUR, but it doesn't work at all. Which may be?

      2.    lesco said

        With the instructions in this post it doesn't work for me either.

      3.    Juank said

        Install it from the AUR:
        $yaourt -S hosty

        and run it:
        $ sudo host

        regards

      4.    lesco said

        I do it that way, but it doesn't work at all. I don't see any advertising leaking. I don't know what the problem will be. At the moment I continue with AdBlock Plus.
        Thank you.

      5.    yukiteru said

        @lesco checks that the / etc / hosts file contains the new script-created entries. If possible and to review, pass the content of the file through http://paste.desdelinux.net/

      6.    lesco said

        I would say that the / etc / hosts file is practically empty. It only has these lines:

        # Ad blocking hosts generated Mon Mar 2 20:05:48 ART 2015
        # Don't write below this line. It will be lost if you run hosty again.

        When I run "sudo hosty" I get this result:
        http://paste.desdelinux.net/?dl=5110

        Greetings.

      7.    Juank said

        Run the command:
        $ ls -lah / etc / hosts

        and paste the output here.

    2.    lesco said

      @JuanK, thanks for your attention. This is the output of such a command:

      -rw-r – r– 1 root root 0 Mar 2 20:15 / etc / hosts

      1.    Juank said

        Run:
        $ host –debug

        and paste the output of that command and some of the first lines of the file that is indicated after "You can see the results in"

      2.    Juank said

        The command is "hosty –debug"
        It had a bad time, it's "hosty" followed by two hyphens "-" and "debug"

      3.    Juank said

        hosty space hyphen middle hyphen debug

      4.    lesco said

        The output of "hosty –debug":

        http://paste.desdelinux.net/?dl=5112

        The file mentioned after “You can see the results in” is /tmp/tmp.viLL774YmV in my case, and its only lines are:

        # Ad blocking hosts generated Wed Mar 4 23:38:18 ART 2015
        # Don't write below this line. It will be lost if you run hosty again.

        There are no more lines in the file.

  18.   Guille Monor said

    Hello John!

    my thanks for this great development called hosty.
    I was finding addresses that I wanted to add to hosty, some new ads, how could I and others collaborate so that you add them to the "repository" of ads?

    greetings from ARG

    Guille

  19.   Felipe said

    Hello,
    Can you put that in a smartphone that has ubuntu, or do you have to change something to adapt it? And if the answer is yes, then what size is it more or less after being put on? to know if I have enough space.
    Thank you

  20.   Pablo said

    The script fails on distros like Gentoo that don't use sudo by default. You should make a version without sudo and indicate that the cronjob will have to be created in the administrator's cron.

    Otherwise, excellent idea. Something comfortable like Adaway was needed but for Linux.
    Greetings.

  21.   Marcelo said

    Many thanks!!! Very obrigado !!!

  22.   gato2707 said

    In early February 2016, the program was altered to become an instrument of censorship. A more extensive explanation in:

    https://elgatoconlinux.wordpress.com/2016/02/20/bloquear-publicidad-no-es-lo-mismo-que-el-activismo-politico-o-la-censura-moralina/

    1.    S said

      Hi. I am the author of the change and therefore of having screwed up, because that change is an unintended error.

      The script was modified as explained in the commit to allow two things
      1- That the script could use fonts in zip and in .7z
      2- That the user could add sources without having to put them in the script
      (You can verify it in the comment of the merge that introduces the error you mention).

      First I found several sources in zip and 7z and I thought it was interesting that the script could handle them, so I added them (I put all the ones I found to test better, that's why there is everything) to test the necessary modifications so that I could unzip and add them to the result.

      Then I wanted to test the aede list as well and added it.

      During all this I realized that this prevented me from uploading the changes to the project because these sources, as you say, should not be in the script. So from there came the other modification that I was commenting on: that the user could add sources (via ~ / .hosty) without having to modify the script.

      Due to lack of time, I made all these changes discontinuously and it seems that I forgot to remove the script sources before doing the merge.
      To add insult to injury, they accepted my "pull request" without realizing this error.

      I think it's understandable that no one was going to include those sources hoping that neither the original author who has to accept the pull request nor the end users were going to notice. It was simply a mistake.

      I hope I have clarified what happened and I ask you please to modify your post so that it is reflected.

      Thank you very much and sorry for the inconvenience.

  23.   ivan said

    Hello John! I've been using this script since you posted it… but now it doesn't remove YouTube ads anymore….

    could you fix it ??

    thank you!

    regards!

  24.   Predatux said

    Good.
    I've been using hosty on Gnu / Linux for quite some time now. I'm trying to get it to work on Mac, could you give me a hand?
    regards