How to block ads and malware websites using /etc/hosts files in Ubuntu

Here’s an easy way to block annoying advertisement and malware sites using ‘/etc/hosts’ file.

First edit the /etc/hosts files using your favorite text editor :

sudo gedit /etc/hosts

Then, paste the list of ads/malware servers in the ‘hosts’ file. You can get the list from http://someonewhocares.org/hosts/ or by searching through Google.

Close the file, and Save. The change will take effect immediately after that. One of the side-effect from this modfication is that your web surfing experience would be significantly faster because your browser does not have to wait for the annoying advertisement to load.

5 Replies to “How to block ads and malware websites using /etc/hosts files in Ubuntu”

  1. wong, because 0.0.0.0 directly denies the ip addresss.. if I use 127.0.0.1, it would take a while for the browser/application to figure out that localhost (127.0.0.1) does not have that service.

    furthermore, if you install apache (or other webserver) on your pc, it will use 127.0.0.1 ip address, if that happen then all the ads will display the homepage of your webserver :)

  2. I see… Shit! I always use “sudo nautilus”… I miss the old version where we can directly login as “root” to the desktop :(

    Oh, why is that you use 0.0.0.0 as the address and not 127.0.0.1 as stated in the URRL you provided?

  3. wong, you shouldn’t use “sudo nautilus”, you only need to enter the terminal, and type “sudo gedit”.

    nautilus is a file manager (explorer-like clone in GNOME), if you run it as root (via “sudo nautilus”) there’s a chance you might delete some important files that might damage your system.

  4. Just a small question, if I use the “sudo nautilus”, can I save the file? Cause last time I use “sudo nautilus” to edit another file, I get to install the whole system again -__-“

Comments are closed.