http://www.ipdeny.com/ipblocks/data/countries/us.zone
# wget http://www.ipdeny.com/ipblocks/data/countries/us.zone
有了国家的所有 IP 地址,要想屏蔽这些 IP 就很容易了,直接写个脚本逐行读取 cn.zone 文件并加入到 iptables 中:
#!/bin/bash # Block traffic from a specific country # written by vpsee.com COUNTRY="us" IPTABLES=/sbin/iptables EGREP=/bin/egrep if [ "$(id -u)" != "0" ]; then echo "you must be root" 1>&2 exit 1 fi resetrules() { $IPTABLES -F $IPTABLES -t nat -F $IPTABLES -t mangle -F $IPTABLES -X } resetrules for c in $COUNTRY do country_file=$c.zone IPS=$($EGREP -v "^#|^$" $country_file) for ip in $IPS do echo "blocking $ip" $IPTABLES -A INPUT -s $ip -j DROP done done exit 0
netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20 | netstat -ant |awk '/:80/{split($5,ip,":");++A[ip[1]]}END{for(i in A) print A[i],i}' |sort -rn|head -n20
把请求过多的IP记录下来。
174.127.94.* 199.27.128.* 199.27.133.*
运行下面这行命令,来查看谁的访问量最高(需要服务器安装tcpdump)
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes 1000 packets captured 1000 packets received by filter 0 packets dropped by kernel 1420 IP 174.7.7.*
本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/1427328