Nginx+iptables 防DDOS,恶意访问,采集器

运维 系统运维
iptables 是与最新的 2.6.x 版本Linux 内核集成的 IP 信息包过滤系统。我们的网站经常遇到不明的DDOS,恶意访问,采集器的骚扰,有没办法解决呢?文章里就能找见办法!

Nginx+iptables DDOS,恶意访问,采集器的骚扰非常讨厌,我想了个办法供大家参考:

  通过分析nginx的日志来过滤出访问过于频繁的IP地址,然后添加到nginx的blockip.conf,并重启nginx

  脚本如下:

  #!/bin/sh

  nginx_home = /Data/app_1/nginx

  log_path = /Data/logs

  /usr/bin/tail -n50000 $log_path/access.log \

  |awk ‘$8 ~/aspx/{print $2,$13}’ \

  |grep -i -v -E “google|yahoo|baidu|msnbot|FeedSky|sogou” \

  |awk ‘{print $1}’|sort|uniq -c |sort -rn \

  |awk ‘{if($1>150)print “deny “$2″;”}’> $nginx_home/conf/vhosts/blockip.conf

  /bin/kill -HUP `cat $nginx_home/nginx.pid`

  也可以通过分析nginx日志过滤出频繁访问IP,直接用iptables屏蔽这个IP,就用不着重启nginx了,并且屏蔽效果更好。

#p#

  单个IP的命令是

  iptables -I INPUT -s 124.115.0.199 -j DROP

  封IP段的命令是

  iptables -I INPUT -s 124.115.0.0/16 -j DROP

  封整个段的命令是

  iptables -I INPUT -s 194.42.0.0/8 -j DROP

  封几个段的命令是

  iptables -I INPUT -s 61.37.80.0/24 -j DROP

  iptables -I INPUT -s 61.37.81.0/24 -j DROP

  刚才不小心搞的自己都连不上了-_-!!!

  iptables -I INPUT -p tcp –dport 80 -s 124.115.0.0/24 -j DROP

  以后用这种只封80端口就行了,不会出问题!

  iptables -I INPUT -p tcp –dport 80 -s 124.115.0.0/24 -j DROP

  iptables -I INPUT -s 61.37.81.0/24 -j DROP

  解封

  iptables -F

  清空

  iptables -D INPUT 数字

  ___________________________________

  #!/bin/sh

  nginx_home = /usr/local/nginx

  log_path = /home/wwwroot/logs

  /usr/bin/tail -n50000 $log_path/access.log \

  |awk ‘$8 ~/aspx/{print $2,$13}’ \

  |grep -i -v -E “google|yahoo|baidu|msnbot|FeedSky|sogou” \

  |awk ‘{print $1}’|sort|uniq -c |sort -rn \

  |awk ‘{if($1>150)print “deny “$2″;”}’> $nginx_home/conf/vhosts/blockip.conf

  /bin/kill -HUP `cat $nginx_home/nginx.pid`

通过文章的介绍,我们找出了Nginx+iptables 防DDOS,恶意访问,采集器的办法,希望对你们有用!

【编辑推荐】

  1. iptables 与 asterisk
  2. iptables 范例
  3. iptables match 查找policy
  4. linux iptables layer7 模块 中文howto
  5. iptables 学习笔记
  6. iptables配置备份
  7. Linux系统Iptables端方执行详细讲解
责任编辑:赵鹏 来源: 网络转载
相关推荐

2009-11-18 15:39:43

PHP函数

2021-12-09 15:30:12

采集器开源-iLogtail

2011-02-18 16:07:46

微软 SQL Serv

2019-01-24 15:30:09

TensorFlow机器学习

2012-01-04 11:09:10

Java采集器

2010-04-30 16:03:20

2014-06-06 17:41:38

2013-07-05 15:11:14

恶意解析Apache设置

2018-09-11 08:47:03

2018-08-06 08:11:26

2016-11-23 09:15:13

2018-06-10 15:30:36

2014-04-10 11:13:22

2016-07-07 15:50:42

2012-11-03 16:01:18

2023-10-11 11:42:27

2023-03-22 18:10:34

2016-10-20 14:22:46

2011-03-17 15:16:38

2010-11-09 13:20:10

网康科技恶意下载
点赞
收藏

51CTO技术栈公众号