- 论坛徽章:
- 0
|
近来网站访问量异常增长,通过分析apache access_log找出了频繁访问的IP地址,确认是盗链,决定使用iptables封掉.
脚本如下:
# awk '{print $1}' access_log.20110622 |sort |uniq -c |sort -nr |more 15112 183.38.186.60 5289 218.83.160.164 4566 58.61.154.18 4428 183.39.105.113 3169 121.14.162.56 2121 113.108.116.17 1971 121.14.162.46 1614 121.14.162.65 1515 192.168.39.134 1430 59.152.221.14 1391 121.14.162.47 1350 183.38.181.117 1317 183.38.189.202 1293 121.14.162.85 1285 121.14.162.117
iptables的使用方法如下:
封单个IP的命令 iptables -I INPUT -s 183.38.186.60 -j DROP
封IP段的命令 iptables -I INPUT -s 183.38.186.0/16 -j DROP
封整个段的命令 iptables -I INPUT -s 183.38.0.0/8 -j DROP
封几个段的命令 iptables -I INPUT -s 183.38.186.0/24 -j DROP iptables -I INPUT -s 183.38.187.0/24 -j DROP
只封80端口 iptables -I INPUT -p tcp –-dport 80 -s 183.38.186.0/24 -j DROP iptables -I INPUT -s 183.38.186.0/24 -j DROP
删除所有限制项 iptables -F
删除指定限制项
iptables -D INPUT 数字
如 iptables -D INPUT 1
查看iptables配置项 # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination DROP tcp -- 10.200.1.149 anywhere tcp dpt:http
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination #
删除一个配置项 # iptables -D INPUT 1
复核iptables配置项 # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination #
|
|