Linux下防CC攻击:封掉某个ip

来源:互联网 发布:软件测试理论基础知识 编辑:程序博客网 时间:2024/04/28 07:18

什么是CC攻击?CC攻击就是利用大量代理服务器对目标计算机发起大量连接,导致目标

服务器资源枯竭造成拒绝服务。那么如何判断查询CC攻击呢?本文主要介绍了一些Linux

下判断CC攻击的命令。


查看所有80端口的连接数


netstat -nat|grep -i "80"|wc -l


对连接的IP按连接数量进行排序


netstat -anp | grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr


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


#链接最多的前20

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


netstat -ntu | awk '{print $5}' | egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" | sort | uniq -c | sort -nr



  1. 查找较多time_wait连接  
  2.   
  3. netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20  
  4. 查找较多的SYN连接  
  5.   
  6. netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more  



查看TCP连接状态


netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn


netstat -n | awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn


netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'


netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'


netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'


netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c


查看80端口连接数最多的20个IP


cat /www/web_logs/waitalone.cn_access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -100


tail -n 10000 /www/web_logs/waitalone.cn_access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -100


cat /www/web_logs/waitalone.cn_access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -100


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}' |sort -rn|head -n20


用tcpdump嗅探80端口的访问看看谁最高


tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20


查找较多time_wait连接


netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20


查找较多的SYN连接


netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more


linux下实用iptables封ip段的一些常见命令:


封单个IP的命令是:



iptables -I INPUT -s 211.1.0.0 -j DROP


封IP段的命令是:


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


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


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


封整个段的命令是:


iptables -I INPUT -s 211.0.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


想在服务器启动自运行的话有三个方法:


1、把它加到/etc/rc.local中


2、iptables-save >/etc/sysconfig/iptables可以把你当前的iptables规则放到/etc/sysconfig/iptables中,系统启动iptables时自动执行。


3、service iptables save 也可以把你当前的iptables规则放/etc/sysconfig/iptables中,系统启动iptables时自动执行。


后两种更好此,一般iptables服务会在network服务之前启来,更安全。


解封的话:


iptables -D INPUT -s IP地址 -j REJECT   #此命令执行后提示:no chain/target/match by that name.


要封停一个IP,使用下面这条命令:

iptables -I INPUT -s ***.***.***.*** -j DROP

要解封一个IP,使用下面这条命令:

iptables -D INPUT -s ***.***.***.*** -j DROP

参数-I是表示Insert(添加),-D表示Delete(删除)。后面跟的是规则,INPUT表示入站,***.***.***.***表示要封停的IP,DROP表示放弃连接。




iptables -F 全清掉了


0 0