我运行的是Apache 2 / MySQL的Centos 6.0服务器。 我有iptables运行。 今晚我按照这些步骤使用iptables阻止来自IP的所有stream量:
iptables -A INPUT -s xxx.xxx.xxx.xxx -j DROP iptables -A OUTPUT -d xxx.xxx.xxx.xxx -j DROP service iptables save service iptables restart
但是我仍然在Apache访问日志中不断地看到来自这个IP的命中,即使在我重新启动Apache之后。 iptables肯定是在运行,这绝对是正确的IP地址。
这些是我的iptables条目的其余部分:
Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- anywhere anywhere 2 REJECT all -- anywhere loopback/8 reject-with icmp-port-unreachable 3 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED 4 ACCEPT tcp -- anywhere anywhere tcp dpt:http 5 ACCEPT tcp -- anywhere anywhere tcp dpt:https 6 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:30000 7 ACCEPT icmp -- anywhere anywhere icmp echo-request 8 REJECT all -- anywhere anywhere reject-with icmp-port-unreachable Chain FORWARD (policy ACCEPT) num target prot opt source destination 1 REJECT all -- anywhere anywhere reject-with icmp-port-unreachable Chain OUTPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- anywhere anywhere
我错过了什么?
起初我会build议你使用system-config-firewall或者system-config-firewall-tui 。 有一个“自定义规则”部分将为您做这个。
如果您想手动执行此类操作,则必须在tcp dpt:http的“ACCEPT”之前插入规则。 最简单的方法是: iptables -I INPUT 1 -s xxx.xxx.xxx.xxx -j DROP
(插入位置1,而不是追加)
你的第一个iptables规则允许你试图阻止的stream量。
1 ACCEPT all -- anywhere anywhere
订单很重要。
由于你的问题已经解决了,让我加一个旁边:你的INPUT链已经有策略设置为ACCEPT。 接受所有stream量的规则不仅会扰乱防火墙,而且与策略的工作方式不同(取决于接受规则的链中的哪个位置),这也是多余的 – 这使得debugging无用且困难。 不要在防火墙中覆盖同样的东西两次。
你可以看到IP,因为你有接受RELATED和ESTABLISHED会话的规则:
3 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
你需要从阻止的IP va tcpkill中终止连接,并且IP将不再连接:)