Editor's Note: Tip Top Tips is a semi-monthly column in The PCLinuxOS Magazine. Periodically, we will feature -- and possibly even expand upon -- one tip from the PCLinuxOS forum. The magazine will not accept independent tip submissions specifically intended for inclusion in the Tip Top Tips column. Rather, if you have a tip, share it in the PCLinuxOS forum's "Tips & Tricks" section. Your tip just may be selected for publication in The PCLinuxOS Magazine.
This month's tip comes from hakerdefo.
pmiab (Poor Man's Internet Ad Blocker) is a simple bash script that blocks ads and other unwanted nasty stuff and makes surfing the ocean of Internet faster, better and safer experience. There is no need to install any browser extension-addon. And the ad blocking done by pmiab will work across every installed browser.
Save the pmiab script given below somewhere in your $PATH, give it necessary permissions (chmod 755) and run it from your terminal as root or with sudo i.e.
su -c pmiab
Then you can enable or disable advert blocking via a simple interactive menu of pmiab. To block the ads, select Block Internet Adverts option from the menu. It is advised that you update the ad-blocking hosts file at-least once in a week. To update the ad-blocking hosts, you need to simply select Block Internet Adverts option from the menu again. In case you want to stop ad blocking via pmiab and want to restore your original hosts file, just select Unblock Internet Adverts from the menu. Simple, ain't it.
Feedback-Response-Critique is demanded. Enough rant. Here is the script:
Later on in the thread, ternor asked, "Presumably it is not possible to disable ad-blocking for a particular web site or domain?"
hakerdefo had a reply:
It is definitely possible! But not in the current version of the script! I can add it if demand is there. In the meanwhile it is very easy to manually white-list (Exclude it from being blocked by pmiab) a site while using pmiab. Suppose I want to white-list foobar.com, All i need to do is open terminal and run:
gksu pluma /etc/hosts.allow
And in that file add the following line:
Save the file. Voila! pmiab from now on won't block any content from foobar.com.
Forum member orblin came up with a slightly different solution for allowing ads on certain sites, and the solution is included in the script above.
Create a file in the same directory as pmiab.sh, and name it allow.txt.
Put the addresses to be unblocked in allow.txt in the following manner: 0.0.0.0 then a tab then the address to be unblocked.
So in this case the entry would be:
In the pmiab script, the code is:
Be aware that the allow.txt file must exist in the same directory as pmiab.sh.
orblin went on to make additional enhancements to block malicious sites, trackers and YouTube ads. These do NOT appear in the script above, but you can insert the following lines of code where indicated with the line that appears in red text, #insert additional block filters here.
"I've added Youtube and No-track's malicious sites and tracker block lists to my script. Here is the code, if it's something you might be interested in.
"The code needs to be added before the existing block list download code as it runs sed to add a 0.0.0.0 prefix to the No-track addresses."