曲径通幽论坛

标题: 为什么无法禁止 ping ? [打印本页]

作者: beyes    时间: 2015-4-2 13:50
标题: 为什么无法禁止 ping ?
在使用 14.07 时,发现直接运行下面的命令:
  1. iptables -A INPUT -p icmp -j DROP
复制代码

不能禁止 ping 了,及时将这个规则写到 firewall.user 里也不行,经过一番考察,发现了问题,原来是防火墙规则的顺序造成的。

解决办法有两,直接在 /etc/config/firewall 里添加 UCI 配置项:
  1. config rule
  2. option name 'Not-Ping'
  3. option src 'lan'
  4. option proto 'icmp'
  5. option icmp_type 'echo-request'
  6. option family 'ipv4'
  7. option target 'DROP'
复制代码


重启防火墙后,再用 iptables --list 查看一下,可以看到:
Chain zone_lan_input (1 references)
target     prot opt source               destination
input_lan_rule  all  --  anywhere             anywhere             /* user chain for input */
DROP       icmp --  anywhere             anywhere             icmp echo-request /* Not-Ping */
ACCEPT     all  --  anywhere             anywhere             ctstate DNAT /* Accept port redirections */
zone_lan_src_ACCEPT  all  --  anywhere             anywhere


在别的机器上 ping 一把,OK 没问题,ping 不通。

现在屏蔽掉上面的配置项,直接用 iptables -A zone_lan_input -p icmp -j DROP 命令来试试看,可以看到:
[attach]4024[/attach]

DROP 规则排在了第 4 条,而第 2 条则是都接受的。这是因为,当系统检查到来自内网的访问匹配这个项时,就不再往下继续匹配,因此要想我们的设置生效,应该用 -I 选项,比如可用:
  1. iptables -I zone_lan_input 1 -p icmp -j DROP
复制代码

将其插入到第一条中去,这样禁止 ping 的规则就生效了。

这种情况可能并不普遍,有些人会遇到,有些人不会遇到。





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2