[HOW-TO] Using ipset
As I suspected, no performance degradation revealed while using over a 6000 strings ipset filter on my 30Mbps internet connection. This is a first approach to new HOW-TO.
Ipset feature will be a part of next Merlin's release, if you wish to try it right now, please use this build for RT-N66U:
RT-N66U_3.0.0.4_270.26_ipset.trx and please note:
…ipset IS targeted at technical people. …ipset is just an iptable extensions that makes it more efficient to block a whole range of IPs, and can be used for many other reasons beyond just ad blocking.
There will be no any WEB UI ipset page or something, it's a command line tool for geeks
It's my working script, fast and dirty. This is NOT for ad-blocking, but for preventing hacker's/scanner's attacks by blocking incoming connections from certain IP addresses. Will add some fool-proof later. Script divided to three parts, started with (#) signs:
- loading ipset modules,
- defining rules to block traffic from Tor nodes,
- defining rules to block traffic from specific countries,
Please, enable JFFS form WEB UI, put this content to
/jffs/scripts/firewall-start file:
Code:
#!/bin/sh
# load ipset modules
IPSET_PATH=/lib/modules/2.6.22.19/kernel/net/ipv4/netfilter
insmod $IPSET_PATH/ip_set.ko
insmod $IPSET_PATH/ip_set_nethash.ko
insmod $IPSET_PATH/ip_set_iphash.ko
insmod $IPSET_PATH/ipt_set.ko
# block traffic from Tor nodes
iptables -D INPUT -m set --set TorNodes src -j DROP
ipset --destroy TorNodes
ipset -N TorNodes iphash
for IP in $(wget -q -O - http://torstatus.blutmagie.de/ip_list_all.php/Tor_ip_list_ALL.csv)
do
ipset -A TorNodes $IP
done
iptables -A INPUT -m set --set TorNodes src -j DROP
# block incoming traffic from some countries.
iptables -D INPUT -m set --set BlockedCountries src -j DROP
ipset --destroy BlockedCountries
ipset -N BlockedCountries nethash
for country in pk cn
do
for IP in $(wget -q -O - http://www.ipdeny.com/ipblocks/data/countries/$country.zone)
do
ipset -A BlockedCountries $IP
done
done
iptables -A INPUT -m set --set BlockedCountries src -j DROP
and make it executable:
Code:
chmod +x /jffs/scripts/firewall-start
You may put (un)desired countries codes to this string
where pk is for Pakistan and cn is for Chine, just for example. Please refer to ipdeny.com/ipblocks/ for full countries list.