zoukankan      html  css  js  c++  java
  • linux ddos防御攻击

    Linux Ddos防御攻击

    [root@lxh ~]# netstat -ntu |awk '{print $5}'|grep '[0-9]'|cut -d: -f1 |sort |uniq -c|sort -n   #查看统计ip链接数

    安装配置ddos deflate

    [root@lxh ~]# cd /usr/local/src

    [root@lxh src]# wget http://www.inetbase.com/scripts/ddos/install.sh

    [root@lxh src]# chmod 744 install.sh    #增加可执行权限

    [root@lxh src]# ./install.sh      #执行安装,安装完后输入q退出说明

    [root@lxh ddos]# cd /usr/local/ddos

    [root@lxh ddos]# ls

    ddos.conf  ddos.sh  ignore.ip.list  LICENSE

    ##############################################################################

    ddos.conf -- DDoS-Deflate 的配置文件,其中配置防止ddos时的各种行为 ddos.sh   -- DDoS-Deflate 的主程序,使用shell编写的,整个程序的功能模块 ignore.ip.list -- 白名单,该文件中的ip超过设定的连接数时,也不被 DDoS-Deflate 阻止 LICENSE   -- DDoS-Deflate 程序的发布协议

    DDoS deflate的默认配置位于/usr/local/ddos/ddos.conf ,默认如下:

    PROGDIR="/usr/local/ddos" PROG="/usr/local/ddos/ddos.sh" IGNORE_IP_LIST="/usr/local/ddos/ignore.ip.list" //IP地址白名单 CRON="/etc/cron.d/ddos.cron" //定时执行程序 APF="/etc/apf/apf" IPT="/sbin/iptables"

    FREQ=1 //检查时间间隔,默认1分钟

    NO_OF_CONNECTIONS=150 //最大连接数,超过这个数IP就会被屏蔽,一般默认即可

    APF_BAN=1 //使用APF还是iptables。推荐使用iptables,将APF_BAN的值改为0即可。

    KILL=1 //是否屏蔽IP,默认即可

    EMAIL_TO="root" //当IP被屏蔽时给指定邮箱发送邮件,推荐使用,换成自己的邮箱即可

    BAN_PERIOD=600 //禁用IP时间,默认600秒,可根据情况调整

    查看/usr/local/ddos/ddos.sh文件的第117行

    netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr > $BAD_IP_LIST

    修改为:

    netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sed -n ‘/[0-9]/p’ | sort | uniq -c | sort -nr > $BAD_IP_LIST

    在crontab中添加没分钟执行ddos.sh脚本

    # crontab -e

    */1 * * * * /bin/bash /usr/local/ddos/ddos.sh

    测试ddos防御。

    测试工具ab,源码安装Apache2一般有安装ab。可用which ab查看是否有安装。

    如果没有安装可执行

    # yum -y install httpd-tools

    [li@lxh1 Desktop]$ ab -n 150 192.168.0.102/

    [root@lxh ~]# netstat -ntu |awk '{print $5}' |cut -d: -f1 |grep '[0-9]' |sort |uniq -c |sort -nr

         151 192.168.0.101

          1 23.32.248.91

    [root@lxh Desktop]# iptables -L

    Chain INPUT (policy ACCEPT)

    target     prot opt source               destination         

    DROP       all  --  192.168.0.101        anywhere 

    这样就禁止了192.168.0.101的访问。

    [root@lxh Desktop]# iptables -F    #清除规则

    [root@lxh Desktop]# service iptables save   #保存规则

  • 相关阅读:
    SpringBoot+SpringCloud+vue+Element开发项目——集成Druid数据源
    SpringBoot+SpringCloud+vue+Element开发项目——集成MyBatis框架
    c语言double类型数据四舍五入
    陀螺仪、加速计、磁力计等传感器汇总 (转)
    sudo和man的tab自动补全
    linux系统资源网站
    gstreamer
    version `GLIBC_2.14' not found 解决方法.
    项目框架设计模式(转)
    Linux音频编程指南(转)
  • 原文地址:https://www.cnblogs.com/rohero/p/5264037.html
Copyright © 2011-2022 走看看