全球主机交流论坛

标题: debian 7 的 iptables 不稳定啊 [打印本页]

作者: 21andy    时间: 2014-7-11 10:20
标题: debian 7 的 iptables 不稳定啊
你们有没有发现啊?
postrouting forward 有时候会自动失效,找不出原因
iptables-restore 也无效
只能把规则写成脚本,全清再运行几次才可以

作者: greensnow    时间: 2014-7-11 11:56
重启了?
作者: 21andy    时间: 2014-7-11 12:05
无重启,而且只有 postrouting forward 自动失效,其他规则不影响
其实就是TNND影响我扶墙啊
作者: lazyzhu    时间: 2014-7-11 12:06
iptables-persistent
作者: 21andy    时间: 2014-7-11 12:07
lazyzhu 发表于 2014-7-11 12:06
iptables-persistent

没用
作者: 21andy    时间: 2014-7-11 12:12
iptables-persistent 的脚本我看过,也用过其他脚本
都会偶尔在重启之后,forward 规则不生效
最严重的,是机器在良好运行的时候,偶尔突然失效
作者: tyucom    时间: 2014-7-11 13:54
原来都有这个体会。  
我还以为是我系统问题。

有时失效,搞得我重启VPS


看来还是 Centos 的  service iptables  restart 简单
且保存也简单  service iptables save
作者: 大胡子    时间: 2014-7-11 13:57
http://www.vpser.net/security/linux-iptables.html
  1. 创建/etc/network/if-post-down.d/iptables 文件,添加如下内容:

  2. #!/bin/bash
  3. iptables-save > /etc/iptables.rules
  4. 执行:chmod +x /etc/network/if-post-down.d/iptables 添加执行权限。

  5. 创建/etc/network/if-pre-up.d/iptables 文件,添加如下内容:

  6. #!/bin/bash
  7. iptables-restore < /etc/iptables.rules
  8. 执行:chmod +x /etc/network/if-pre-up.d/iptables 添加执行权限。
复制代码

作者: yohu    时间: 2014-7-11 14:13
debian 7下一直用csf,无压力。
作者: guyusoftware    时间: 2014-7-11 16:05
大鬍子說的或是csf都行 csf其實方法類似吧我記得
作者: 21andy    时间: 2014-7-11 18:21
大胡子 发表于 2014-7-11 13:57
http://www.vpser.net/security/linux-iptables.html

这个没用的,刚开始就是这么干的,还以为是这样干不行,换iptables-persistent, 还是一样,再换另外的一个init script, 还是不行,才想到跟脚本应该没有关系, 是debian 自己的问题
如果是没有restore进来,应该规则全失效,怎么会只有一两条失效
我设置是一次性批量脚设置的

作者: 21andy    时间: 2014-7-11 18:45
典型症状是这样的
我什么都搞好了,一切正常的很,系统也不重启
一段时间后,几个小时,或者一两天,突然间
PPT*能连上,但不能上外网,其他iptables规则一切正常
然后,我PP*P连接不断开,接着
然后,ssh上去,iptables-restore < ...rules, 没用
然后, iptables -A FORWARD ... POSTROUTING ... 没用
然后,运行脚本, 脚本包含全清和重新添加所有规则
iptables -  ...
iptables -  ...
iptables -  ...
还是没用!,再运行一次,没用,再运行一次,好了!我都没重新连PP*P

以上过程整个期间,系统未重启, 所有服务都没重启,也没停止
换 centos 同样规则不会这样, centos的iptables稳定多了

目前暂时的解决办法,是把自己的脚本放在 /usr/local/bin/autoset_iptables
出问题的时候,就运行几次,问题出的多了,我干脆加到 cron 里面2分钟一次,这样就没问题了
另外,echo '/usr/local/bin/autoset_iptables' >> /etc/rc.local 不用其他 iptables-restore 脚本,这个可以解决偶尔启动时iptables-restore不生效的问题





欢迎光临 全球主机交流论坛 (https://loc.mjj8.eu.org/) Powered by Discuz! X3.4