我需要阻止一些使用ipset和iptables的国家。
我到目前为止所做的(创build新的ipset set'geoblock'):
sudo ipset create geoblock hash:net,port
然后我创build了以下脚本/usr/sbin/ipsetfirewall.sh
#!/bin/bash for IP in $(wget -O – http://www.ipdeny.com/ipblocks/data/countries/{cn,iq,af,ir,ae,sg,hk,kw,kg}.zone) do # ban everything – block countryX sudo ipset add geoblock $IP done
正如我在这里解释的,我也试过
wget -O – http://www.ipdeny.com/ipblocks/data/countries/{cn,iq,af,ir,ae,sg,hk,kw,kg}.zone --header "Referer: www.ipdeny.com"
我也试过(因为我使用的是ipv4)
wget -4 http://www.ipdeny.com/ipblocks/data/countries/{cn,iq,af,ir,ae,sg,hk,kw,kg}.zone
对于我所有的尝试,我得到这个相同的错误:
/usr/sbin$ sudo sh ipsetfirewall.sh --2016-04-21 15:40:58-- http://www.ipdeny.com/ipblocks/data/countries/%7Bcn,iq,af,ir,ae,sg,hk,kw,kg%7D.zone Resolving www.ipdeny.com (www.ipdeny.com)... 192.241.240.22 Connecting to www.ipdeny.com (www.ipdeny.com)|192.241.240.22|:80... connected. HTTP request sent, awaiting response... 404 Not Found 2016-04-21 15:40:59 ERROR 404: Not Found.
有什么问题?
你可以试试这个脚本: http : //www.cyberciti.biz/faq/block-entier-country-using-iptables/
我前段时间用过,为我工作
抓住所有区域的效率可能更高
wget http://www.ipdeny.com/ipblocks/data/countries/all-zones.tar.gz tar -xzf all-zones.tar.gz
否则,一次一个
for C in cn iq af ir ae sg hk kw kg ; do wget -4 http://www.ipdeny.com/ipblocks/data/countries/${C}.zone done