Create an ipset based blocklist from an text file (downloaded from e.g. blocklist.de)
Written and tested on Debian Wheezy!
Create an ipset based blocklist from multiple url to an blocklist text file e.g. blocklist.de.
Changes
--------
V1.1.0: blocklist-with-ipset is now IPV6 compatible (Yayyy :) )
- V1.1.0: blocklist-with-ipset is now IPV6 compatible (Yayyy :) )
- V1.0.4: Path to white and blacklist is now set automatically
- V1.0.3: Now you can set multiple blocklist sources
- V1.0.2: Added a whitelist and blacklist
<br>
**!!! IMPORTANT !!!!**
V1.0.4: Path to white and blacklist is now set automatically
When upgrading from a version lower than 1.1.0 you might have tomanually drop duplicated INPUT Rules.
V1.0.3: Now you can set multiple blocklist sources
This should be an time issue though!
V1.0.2: Added a whitelist and blacklist
## INSTALL ##
1. Make sure you have ipset installed! If not you can usually install it with your distribution software management tool. E.g. apt for Debian/Ubuntu/Mint.
!!! IMPORTANT !!!!
apt-get install ipset
When upgrading from a version lower than 1.1.0 you might have to manually drop duplicated INPUT Rules.
2. Download the ZIP, or Clone the repository, to a folder on your system.
3. Open blocklist.pl with your favorite text editor and set up your blocklist urls. Two are included as default. You can enhance or edit as you like. The destination URL should be an direct link to an Text file though.
my @listUrl = ("http://lists.blocklist.de/lists/all.txt", "http://www.infiltrated.net/blacklisted");
*You can for example add an list like this*
my @listUrl = ("http://lists.blocklist.de/lists/all.txt", "http://www.infiltrated.net/blacklisted", "http://www.superblocksite.org/anotherBlocklist.txt");
You will need to install ipset!
4. While in blocklist.pl verify the location of your binarys. You can verify them with "which". For example 'which ipset' in an Terminal.
Also you will have to specify where your binarys are located. This settings can be made in blocklist.pl .
(You can find out where your binarys are with "which" e.g. "which iptables")
6. Create an logrotate for the logfile. E.g. under /etc/logrotate.d/blocklist
my $ipset = "/usr/sbin/ipset";
/var/log/blocklist
{
rotate 4
daily
missingok
notifempty
delaycompress
compress
}
my $grep = "/bin/grep";
7. If you have an ip you definitly want to block just put it in blacklist.txt. If you have an IP you definitly never want to have blocked put it in whitelist.txt. This two files are just text lists seperated by new lines. So for example
my $rm = "/bin/rm";
#blacklist.txt
2.2.2.2
3.3.3.3
my $wget = "/usr/bin/wget";
#and in whitelist.txt
4.4.4.4
5.5.5.5
That's it. If you want to manually run the script just cd to the folder where the script is located and run ./blocklist.pl