(Instalación de Peerguardian en Linux y como configurarlo para que se ejecute al inicio del sistema)

Hay mucha información por hay sobre como proteger nuestros PCs usando programas como P2Phazard o Peerguardian, pero siempre bajo el SO Windows. Por eso he decidido escribir este post con las instrucciones para proteger un PC con SO Linux usando la versión de Peerguardian para este SO, que dado que aun se encuentra en fase beta no es muy intuitiva ni sencilla de configurar.

La pagina de Peerguardian la podéis encontrar aquí:http://phoenixlabs.org/, y aquí la sección de Peerguardian para el paquete Debian de Linux:: PeerGuardian Debian
Cada uno tendrá que descargar la que mas convenga a su distribución, yo como uso Ubuntu voy a comentaros todo el proceso para esta distribución (supongo que sera valido para cualquier Debian).
Descargamos el paquete deb y lo instalamos escribiendo como root:
dpkg -i peerguardnf-1.5beta.i386.deb
Ahora ya tenemos Peerguardian instalado en nuestro sistema.

Es importante tener siempre el ordenador protegido, por eso lo mejor es hacer que Peerguardian se ejecute al arrancar el ordenador.
Para ello hacemos lo siguiente:
sudo mkdir /etc/peerguardian
sudo gedit /etc/init.d/peerguardian.sh
y dentro copiamos lo siguiente:
Código: Seleccionar todo
# version for bluetack.co.uk lists!
#!/bin/sh
# Update new blocklists and start/stop/restart PeerGuardian
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# testdescription
#
#CONFIGURATION
# Make sure PG_ETC points to the directory where
# you want to put your downloaded blocklists.
PG_ETC=/etc/peerguardian/
# Remove the lists you don't want to download and
# use from BLOCKLISTS.
BLOCKLISTS="level1"
PG_CONF=/etc/PG.conf
PG_LOG=/var/log/PG.log
PG_LIST=/etc/p2p.p2b.p2p
#The URL where the blocklists reside
URL=http://www.bluetack.co.uk/config
#The format of the lists to download
SUFFIX=gz
#The format after unpacking
SUFFIX2=txt
endscript () {
date +"------------ "%F" "%X" "%Z" End PeerGuardian Script"
exit $1
}
date +"------------ "%F" "%X" "%Z" Begin PeerGuardian $1"
case "$1" in
'start')
cd "$PG_ETC"
# check if blockfiles were updated:
UPDATED=""
for i in $BLOCKLISTS ; do
TIMESTAMP=0
if [ -e $i.$SUFFIX ] ; then
TIMESTAMP=`stat --format=%y $i.$SUFFIX`
echo "File $i.$SUFFIX last updated $TIMESTAMP"
TIMESTAMP=`stat --format=%Y $i.$SUFFIX`
fi
wget -N $URL/$i.$SUFFIX
if [ `stat --format=%Y $i.$SUFFIX` -gt $TIMESTAMP ] ; then
UPDATED=$i
fi
done
# if none of the blockfiles were updated:
if [ -z $UPDATED ] ; then
echo "No blocklists needed updating."
echo "Starting PeerGuardian"
mv $PG_LOG $PG_LOG.backup
peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
endscript 0
fi
# if any blockfiles were updated:
for i in $BLOCKLISTS ; do
gunzip -c $i.$SUFFIX > $i.$SUFFIX2
BLOCKLISTSCAT="$BLOCKLISTSCAT $i.$SUFFIX2"
done
cat $BLOCKLISTSCAT | peerguardnf -f merged.p2b.p2p
for i in $BLOCKLISTS ; do
rm $i.$SUFFIX2
done
# uncomment below to unblock Yahoo! Mail and whatever
# else needs unblocking here. Do this also in the
# restart section.
grep -v -i "yahoo\!" merged.p2b.p2p | grep -v -i "Microsoft" | grep -v "Google" > merged.p2b.p2p.tmp
mv merged.p2b.p2p.tmp merged.p2b.p2p
mv $PG_LIST $PG_LIST.backup
mv merged.p2b.p2p $PG_LIST
mv $PG_LOG $PG_LOG.backup
echo "Starting PeerGuardian"
peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
endscript 0
;;
'stop')
echo "Stopping PeerGuardian"
killall peerguardnf > /dev/null 2>&1
endscript 0
;;
'restart')
cd "$PG_ETC"
# check if blockfiles were updated:
UPDATED=""
for i in $BLOCKLISTS ; do
TIMESTAMP=0
if [ -e $i.$SUFFIX ] ; then
TIMESTAMP=`stat --format=%y $i.$SUFFIX`
echo "File $i.$SUFFIX last updated $TIMESTAMP"
TIMESTAMP=`stat --format=%Y $i.$SUFFIX`
fi
wget -N $URL/$i.$SUFFIX
if [ `stat --format=%Y $i.$SUFFIX` -gt $TIMESTAMP ] ; then
UPDATED=$i
fi
done
# if none of the blockfiles were updated:
if [ -z $UPDATED ] ; then
echo "No blocklists needed updating."
echo "Stopping PeerGuardian"
killall peerguardnf > /dev/null 2>&1
mv $PG_LOG $PG_LOG.backup
sleep 4
echo "Starting PeerGuardian"
peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
endscript 0
fi
# if any blockfiles were updated:
for i in $BLOCKLISTS ; do
gunzip -c $i.$SUFFIX > $i.$SUFFIX2
BLOCKLISTSCAT="$BLOCKLISTSCAT $i.$SUFFIX2"
done
cat $BLOCKLISTSCAT | peerguardnf -f merged.p2b.p2p
for i in $BLOCKLISTS ; do
rm $i.$SUFFIX2
done
# uncomment below to unblock Yahoo! Mail and whatever
# else needs unblocking here. Do this also in the
# restart section.
grep -v -i "yahoo\!" merged.p2b.p2p | grep -v -i "Microsoft" | grep -v "Google" > merged.p2b.p2p.tmp
mv merged.p2b.p2p.tmp merged.p2b.p2p
echo "Stopping PeerGuardian"
killall peerguardnf > /dev/null 2>&1
mv $PG_LIST $PG_LIST.backup
mv merged.p2b.p2p $PG_LIST
mv $PG_LOG $PG_LOG.backup
sleep 4
echo "Starting PeerGuardian"
peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
endscript 0
;;
*)
echo "Usage: $0 { start | stop | restart }"
;;
esac
exit 0
sudo chmod -c 755 /etc/init.d/peerguardian.sh
Ya esta, ahora lo unico que nos queda es añadirlo al inicio:
sudo update-rc.d peerguardian.sh defaults
Ahora ya se arranca al inicio, pero para pararlo, rearrancarlo,...
sudo peerguardian.sh start
sudo peerguardian.sh restart
sudo peerguardian.sh stop

Para ver las IPs que bloquea, pararlo, rearrancarlo,... ponemos el comando pgtext en una terminal. Nos aparecerá una ventana que yo creo que no necesita explicación.
Espero que este mini manual le sea de utilidad a alguien.
saludos