Moblock – Quick and Dirty Fix – Mandriva

2 01 2008

Moblock truly is a requirement for every *nix user that partakes in P2P. Unfortunately the Moblock package from Mandriva’s repositories isn’t all it should be in my opinion. It utilizes the new binary p2p lists – .p2b files from, which I’m not sure if they’re currently active after letting the domain expire in July 07 then having DNS issues later in the year, it’s easier to migrate over to bluetack’s blocklists.

Note: You need to have installed sudo and configured your account as sudoer before you continue; instructions are available here.

I made a quick and dirty script to update moblock and made a few changes to moblocks config file, as well as deleting the created cron job set by the package. This script is really basic, but does exactly what it needs to do – stops moblock, updates the blocklist, complies them into a p2p text file, backups the current blocklist, and moves the new blocklist into /etc, restarts moblock, and runs tail. The script is as follows:

# Update Moblock

#Directory check, if not make directory
if [ -d $HOME/Documents/blocklists ]
echo “Directory exists”
mkdir $HOME/Documents/blocklists
echo “Created Directory”
#Stop moblock
/etc/rc.d/init.d/moblock stop
#change to working directory
cd ~/Documents/blocklists
#Backup old p2p file
cp guarding.p2p guarding.p2p.backup
#Download Bluetack blocklists
#Extract blocklist
gunzip ~/Documents/blocklists -r -v
#Combine blocklists into p2p file
cat level1 level2 level3 ads-trackers-and-bad-pr0n bogon dshield edu hijacked iana-multicast iana-private iana-reserved rangetest spider spyware trojan Microsoft templist >guarding.p2p
#Backup /etc/guarding.p2p
cp /etc/guarding.p2p /etc/guarding.p2p.backup
#copy new/updated blocklist file to /etc
cp guarding.p2p /etc/
#Cleanup individual blocklists
rm level1 level2 level3 ads-trackers-and-bad-pr0n bogon dshield edu hijacked iana-multicast iana-private iana-reserved rangetest spider spyware trojan Microsoft templist
#Restart moblock
/etc/rc.d/init.d/moblock restart
/etc/rc.d/init.d/moblock restart
#Start tail for moblock log file
tail -f /var/log/moblock.log

Let’s make a directory to save the script in, open konsole and enter:

mkdir ~/Documents/my_scripts

We’ll change directories and create a file to save the script in:

cd ~/Documents/my_scripts

touch moblock_up

kwrite moblock_up

Copy and paste the script text into the file and save, then we need to make the file executable:

chmod +x moblock_up

All Bluetack’s blocklist are included in the script so you can remove the ones you don’t need to use or leave exactly as is. [note:] as HTTP is allowed in the moblock config file, you don’t need the ads-trackers-bad-pr0n and spider lists. Remove whatever you don’t feel is necessary (ie. edu – is you don’t wish to block it.

Do we need to make a few alterations to moblocks config file. But let’s first back it up:

sudo cp /etc/sysconfig/moblock /etc/sysconfig/moblock.backup

Now let’s edit the file:

kdesu kwrite /etc/sysconfig/moblock

and change the following:



Close kwrite and save the file. [note] the second half highlighted by itailics isn’t necessary as we’re going to delete the cronjob anyway. ;-)

Backup the cronjob if you wish to your home directory:

mkdir ~/Documents/blocklists/old_cronjob

cp /etc/daily.cron/moblock ~/Documents/blocklists/old_cronjob/

then you can remove the cronjob

sudo rm /etc/daily.cron/moblock

We’re still in the directory the script is in, execute it with:

sudo ./moblock_up

Moblock is now blocking connections to the IP rangesfrom guarding.p2p and you’re seeing the output from the moblock logfile in konsole. Now you can run the script when you want to update moblock [once a week is good enough].

Remember when you restart your PC to restart moblock with (when you want it running/active):

sudo /etc/rc.d/init.d/moblock restart

and then tail the logfile to confirm moblock is actively blocking:

sudo tail -f /var/log/moblock.log

As of today, using all the available blocklist from Bluetack; Moblock should be blocking 337155 ranges. To test or to see moblock in action, open a new shell session in konsole and paste the following:

ping -c4

In the session showing the tail of the moblock logfile, you’ll see:

Blocked OUT: Google Inc,hits: 1,DST:
Blocked OUT: Google Inc,hits: 2,DST:
Blocked OUT: Google Inc,hits: 3,DST:
Blocked OUT: Google Inc,hits: 4,DST:

Another example:

ping -c4

Tail of the Moblock logfile will show:

Blocked OUT: NBC INC-070731163231,hits: 1,DST:
Blocked OUT: NBC INC-070731163231,hits: 2,DST:
Blocked OUT: NBC INC-070731163231,hits: 3,DST:
Blocked OUT: NBC INC-070731163231,hits: 4,DST:

+ additional notes+If you’re using all the available blocklist, as you can see above google is listed in the spider blocklist. Therefore your SSL POP/SMTP access will be blocked, either stop moblock, fetch your gmail through your email client (Web Access is already whitelisted and will not be blocked) and then restart moblock (commands listed below); or add the ports to the whitelist in /etc/sysconfig/moblock.

You can stop moblock with:

sudo /etc/rc.d/init.d/moblock stop

Start and Restart with:

sudo /etc/rc.d/init.d/moblock start

sudo /etc/rc.d/init.d/moblock restart

This is a work in progress, suggestions and comments are always welcome. ;-)

Creative Commons License
This work is licensed under a
Creative Commons Licence.


Blogged with Flock

Tags: , , , ,





6 responses

4 01 2008
Quick and Dirty followup - Different path to achieve the same goal. « alt options

[…] first part of the script isn’t a necessity, it checks to see if the directory relied on by the script is available, if […]

13 03 2008

mandriva doesn’t use sudo, just use su

15 05 2008

Impossible d’installer moblock sou sMandriva 2008.1 64bits !

30 05 2008

Thank you for the write-up. Worked to a tee, I don’t mind getting a little dirty with the command line so it worked out great! Thanks !!!!

14 08 2008

awesome. VERY helpful

1 05 2009

Worked lik ea charm for me, and I been using this same script for along time on more than a few installs.
Its a must have running a TorrentFlux server at home.

Thank You, b366alive

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: