Page 1 of 2 12 LastLast
Results 1 to 10 of 71

Thread: HOWTO: Amend your hosts file to block ads (by site)

Hybrid View

  1. #1
    Join Date
    May 2006
    Beans
    42

    HOWTO: Amend your hosts file to block ads (by site)

    Note: this is very much a beginner's guide.


    Q: What is a HOSTS file / Why might I want to do this?
    A: It's explained nicely at http://www.mvps.org/winhelp2002/hosts.htm


    Q: But why do this in Ubuntu? My Ubuntu is like a shield of steel!
    A: Many reasons. But mainly to save bandwidth by not loading lots of rubbish. For each site listed as 127.0.0.1, content (usually ad banners etc) from that site isn't loaded. In a web browser that picture/frame will 404.

    So, how to do it:
    The host file in Linux lives at /etc/hosts. We are going to add some lines to it.

    Disclaimer:

    ***** NOW HEAR THIS *****

    A) ***BACK UP*** your /etc/hosts BEFORE YOU START

    B) You must APPEND to (not overwrite) the file. You need the stuff that's already in there! That means: paste in the additional lines AFTER what's already in there!

    C) I do not recommend doing this if you HOST WEB PAGES from your PC.


    End of disclaimer.



    1) >>>>>>> BACKUP YOUR HOSTS FILE <<<<<<<<<

    $ sudo cp /etc/hosts /etc/hosts.old

    2) Download a good hosts file. I recommend the MVPs one:

    http://www.mvps.org/winhelp2002/hosts.txt

    3) Open your hosts file.

    $ sudo gedit /etc/hosts

    4) Paste in the contents of hosts.txt into the bottom of /etc/hosts.

    5) It should take effect immediately. Close and reload your web browser then try to go to one of the blocked sites. It should 404.

    Luc

  2. #2
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: HOWTO: Amend your hosts file to block ads (by site)

    Here is a link to a site with a script to update your hosts file:

    hostsfile.mine

    Look on the very bottom of the page for this:

    Unix/Linux bash Hosts updater script (txt) (m)

    Here is the script if you would like to examine the code:

    Hosts update script

    • Download the script
    • Make the script executable (chmod a+x updatehosts.sh)
    • Install tofrodos (sudo apt-get install tofrodos)
    • sudo ./updatehosts.sh


    Optional
    127.0.0.1 = your computer
    0.0.0.0 = nowhere

    "0.0.0.0" is faster as "127.0.0.1" will wait for a timeout


    This command will change 127.0.0.1 to 0.0.0.0 :
    Code:
    sudo sed -i -e 's_127.0.0.1_0.0.0.0_g' /etc/hosts
    WARNING: We now need to manually edit /etc/hosts and change the line(s) at the top with localhost and your hostname back to 127.0.0.1 localhost

    #These may be on one line or multiple lines
    127.0.0.1 localhost
    127.0.0.1 Ubuntu # Change Ubuntu to your hostname
    It is best to do this from the terminal with vim or nano as graphical editors will take forever to load (the hosts file is large).
    Last edited by bodhi.zazen; January 19th, 2008 at 12:20 AM.
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

  3. #3
    Join Date
    Oct 2006
    Beans
    9

    Re: HOWTO: Amend your hosts file to block ads (by site)

    After running the script, which ran seemlessly, I don't see any changes to the HOSTS file... which one should it change? I was hoping to do like I did in ******* and cut/paste the loopbacks into the file, but I lost admin rights when I did it. Maybe I made a n00b mistake, I'll try it again. thanks

  4. #4
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: HOWTO: Amend your hosts file to block ads (by site)

    it modifies /etc/hosts

    If you lost admin rights, boot to failsafe.

    If you do not know, to get your host name, at the CLI type:
    Code:
    hostname
    Code:
    nano /etc/hosts
    Add the line
    127.0.0.1 localhost.localdomain <hostname>
    <hostname> = your host name
    At the top fo the file.

    Crtl-X to exit, type Y to save.

    Reboot
    Code:
    reboot
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

  5. #5
    Join Date
    Aug 2008
    Beans
    31
    Distro
    Ubuntu 10.04 Lucid Lynx

    Thumbs up Re: HOWTO: Amend your hosts file to block ads (by site)

    Thank you very much.

  6. #6
    Join Date
    Mar 2006
    Location
    Rumplestiltskin, Cal.
    Beans
    Hidden!
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: HOWTO: Amend your hosts file to block ads (by site)

    Following this post, I read:

    Unix/Linux bash Hosts updater script (txt) (m)

    Here is the script if you would like to examine the code:

    Hosts update script

    * Download the script
    * Make the script executable (chmod a+x updatehosts.sh)
    * Install tofrodos (sudo apt-get install tofrodos)
    * sudo ./updatehosts.sh


    I downloaded the updatehosts.sh.txt

    but, doing: chmod a+x updatehosts.sh -- did not remove the .txt. So there I quit and am asking for clarification:

    Do I rename the file updatehosts.sh.txt manually before or after running chomd a+x?
    AMD FX-6300, 8gig ddr3, MSI 970 Gaming, 256G WD blue SSD, GeForce GT710, HP LJ Pro M277-fdw

  7. #7
    Join Date
    Feb 2010
    Location
    Zagreb/Croatia
    Beans
    9

    Re: HOWTO: Amend your hosts file to block ads (by site)

    Quote Originally Posted by bodhi.zazen View Post
    Here is a link to a site with a script to update your hosts file:

    hostsfile.mine
    here is my host file if you wish to block porn

    http://datasaver.orgfree.com/hosts.zip
    xthosts no longer works so I had 2 change!
    Last edited by ipernar; September 27th, 2010 at 04:20 PM.

  8. #8
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: HOWTO: Amend your hosts file to block ads (by site)

    Quote Originally Posted by ipernar View Post
    here is my host file if you wish to block porn

    http://user.xthost.info/zelenalista/hosts.zip
    thank you !!

    The zip file does not download =(
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

  9. #9
    Join Date
    Feb 2010
    Location
    Zagreb/Croatia
    Beans
    9

    Re: HOWTO: Amend your hosts file to block ads (by site)

    Quote Originally Posted by bodhi.zazen View Post
    thank you !!

    The zip file does not download =(
    Dude it must download
    just click download (2times) after clicking the link

    One friend of mine was at my apartment (slept over) and he wanted to search for porn on my comp and was shocked to realise he cant get it... hahah

    It was funny to see his face, i said... wazap bro... no porn today... and he said... yeah dude, i searched...but couldnt get into site...

    email me if yoou want me to send it via email
    ipernar@yahoo.com
    Last edited by ipernar; June 10th, 2010 at 08:34 AM.

  10. #10
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: HOWTO: Amend your hosts file to block ads (by site)

    Quote Originally Posted by ipernar View Post
    Dude it must download
    just click download (2times) after clicking the link

    One friend of mine was at my apartment (slept over) and he wanted to search for porn on my comp and was shocked to realise he cant get it... hahah

    It was funny to see his face, i said... wazap bro... no porn today... and he said... yeah dude, i searched...but couldnt get into site...

    email me if yoou want me to send it via email
    ipernar@yahoo.com
    Had to allow cookies to DL the zip file.

    OMG that is one huge hosts file, lol
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •