在我们的服务器上运行top给我们
平均负载:68.67,63.48,60.30
我们怀疑这是来自太多的httpd连接。
运行:
netstat -tun 2>/dev/null | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr
给我们(所有IP转换为私人地址):
418 176 192.168.1.1 41 192.168.1.2 8 192.168.1.3 5 192.168.1.4 5 192.168.1.5 4 192.168.1.6 2 192.168.1.7 2 192.168.1.8 2 192.168.1.9 2 127.0.0.1 1 servers) 1 Address 1 192.168.1.10 1 192.168.1.11
正如你可以看到192.168.1.1 (从广域网地址转换,就在这里),它似乎有176连接到我们的服务器。 远程查看此IP会将其parsing为DDOS服务。
我们跑了
sudo iptables -I INPUT -m iprange --src-range 192.168.0.0-192.168.0.255 -j DROP
尝试删除与其全范围相关的所有范围,但运行netstat命令时仍然显示请求。
IPtables命令或netstat命令有什么问题吗?
我们跑
sudo service iptables save sudo service httpd restart
存储它,然后使其活动
sudo iptables --list
确认它被添加了,这是。 不知道是否有什么我们错过了。 谢谢。
UPDATE
运行iptables -L -nv显示
pkts bytes target prot opt in 30179 1793K DROP all -- * * 0.0.0.0/0 0.0.0.0/0 source IP range STARTRANGE-ENDRANGE
这是否意味着30179请求被阻止?
也是我们的IPtables看起来像这样(STARTRANGE / ENDRANGE是实际的四字节地址)…
Chain INPUT (policy DROP) target prot opt source destination DROP all -- anywhere anywhere source IP range STARTRANGE-ENDRANGE DROP all -- anywhere anywhere source IP range STARTRANGE-ENDRANGE DROP all -- anywhere anywhere source IP range STARTRANGE-ENDRANGE ACCEPT tcp -- anywhere anywhere tcp dpt:http ACCEPT tcp -- anywhere anywhere tcp dpt:https ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT icmp -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh ACCEPT tcp -- anywhere anywhere tcp dpt:mysql DROP all -- anywhere anywhere source IP range STARTRANGE-ENDRANGE
缩短的Netstat输出(命令运行: netstat -n | grep '192.168' ):
tcp 0 1 OUR_SERVER_IP:44531 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44675 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44600 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44587 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44641 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44578 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44626 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44604 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44541 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44678 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44625 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44661 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44543 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44602 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44644 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44580 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44688 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44683 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44588 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44556 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44681 192.168.1.1:443 SYN_SENT tcp 0 1 OUR_SERVER_IP:44631 192.168.1.1:443 SYN_SENT
现在,您终于发布了netstat输出问题(谢谢),我们可以看到,几乎可以确定的连接不是来自远程服务器,正如您所想的那样。 相反,您的服务器正尝试在端口443(HTTPS)上启动到该远程服务器的连接。 这就是为什么他们没有被INPUT链规则阻止的原因。 第一个数据包是出站的 – 只有远程服务器生成的响应被INPUT规则阻塞,将连接保留在SYN_SENT直到超时。
netstat -apn使用已经表明它是你的系统上正在build立这些连接的HTTPD服务器。 你不知道为什么你的服务器应该这样做的原因,所以你要走了很长时间仔细看看它的设置。
如果规则匹配,可以使用iptables -L -nv进行故障排除。 您将在第一列中看到与每个规则匹配的数据包数量。
如果您的规则不匹配,则可能是之前由另一个防火墙条目(规则)匹配。
确保使用rulenum参数运行iptables -I INPUT (...) 。 你想确保这个规则被插入到http端口的任何-j ACCEPT规则之前。 这个参数的默认值是1,所以它应该已经在顶部了。
iptables -nvL --line-numbers将打印出你的当前iptables与规则的数字。
$ iptables -nvL --line-numbers Chain INPUT (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination 1 52 2640 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80 2 0 0 ACCEPT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443 3 415 42229 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
运行iptables -I INPUT 2 <your-rule-here>将在输出中的规则#2之前添加规则,并在表中将其推下。
你可以用iptables -I INPUT -m iprange --src-range 192.168.0.0-192.168.0.255 -j LOG --log-prefix "BADGUYS"replace你的规则iptables -I INPUT -m iprange --src-range 192.168.0.0-192.168.0.255 -j LOG --log-prefix "BADGUYS"而不是-j DROP 。 这会将日志数据写入系统日志,您可以在BADGUYS按照上面给出的BADGUYS值进行过滤。 如果这显示在系统日志中,那么你的filter是好的,应该丢弃stream量。
你可以在一个iptables规则中保留一个LOG和DROP行(按照这个顺序)。