曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 6082|回复: 0
打印 上一主题 下一主题

[iptables] 为什么无法禁止 ping ?

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2015-4-2 13:50:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在使用 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 命令来试试看,可以看到:


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

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

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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-3 12:40 , Processed in 0.078933 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表