centos - Iptable 不会丢弃传入或传出的数据包

标签 centos iptables

我正在使用 CentOS。

我在我的 IPTable 测试环境中完成了以下操作。我已经刷新了所有规则,使用

    iptables -F 

然后我添加了以下规则。

    iptables -I INPUT -p all -j ACCEPT

然后根据观察,我添加了这条规则;

    iptables -A INPUT -s 192.168.2.50 -j DROP

我已经运行了

    service iptable save

之后我尝试 ping 被阻止的 ip (192.168.2.50)。我仍然可以 ping 它,被阻止的 ip 可以 ping 我。

我想阻止任何来自被阻止 IP 的传入连接。

这是我对 iptables -L

的输出
    Chain INPUT (policy DROP) target prot opt source destination

    ACCEPT all -- anywhere anywhere
    DROP all -- 192.168.2.50 anywhere

    Chain FORWARD (policy DROP) target prot opt source destination

    Chain OUTPUT (policy ACCEPT) target prot opt source destination

    Chain icmp_packets (0 references) target prot opt source destination

    Chain tcp_packets (0 references) target prot opt source destination

请帮忙..谢谢..

最佳答案

Iptables 使用规则链。在链中,规则按顺序应用于数据包,从第一个(在顶部)到最后一个。 您的第一个规则 ACCEPT all -- anywhere anywhere 让所有通过链的数据包都被接受,因此它们不会进一步进入下一个应该丢弃所有的规则。 因此,如果你只想丢弃所有到你机器的流量,只需使用 iptables -D INPUT 1 删除你的第一条规则,这将删除输入链中的第一条规则,只留下丢弃所有规则.然后用 iptables -A INPUT -p all -j ACCEPT 再次添加接受所有规则,这样所有不是来自被阻止的 ip 的数据包都将被允许通过。

关于centos - Iptable 不会丢弃传入或传出的数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17159917/

相关文章:

linux - 用iptables打开端口不起作用

linux - 错误 : iptables v1. 4.21:icmp:必须指定选项 "--icmp-type"

linux - 无法通过端口转发从主机连接到 Vagrant (ubuntu/trusty64)

linux - 无法在 IPTABLES 防火墙上打开端口

iptables 规则将 ICMP(Ping) 流量限制为每秒 5 个数据包

php - Centos/PHP 升级后服务器宕机

centos - 如何从中恢复

php - 准备好的语句的安全/服务器系统日志记录

Docker exec rpc 错误代码 =13 desc = 无效的 header 字段值 "oci runtime error: exec failed: cannot exec a container that has run and stopped\n"

centos - openldap 无法绑定(bind) ldaps ://127. 0.0.1:636