系统升级到CentOS 7后总感觉iptables怪怪的,比如不管怎么保存重启后都被初始化一下,即便我最后发大绝招启动时候加命令: 首先iptables-save > /etc/iptables.rules保存当前状态。 然后再在/etc/rc.local中强制加上

iptables-restore /etc/iptables.rules

重启后虽然规则生效但仔细看规则还是一些被莫名添加的额外的内容,让人很是不爽。

仔细一google,发现问题之所在了。RedHat在7中更改了系统软件,不再使用iptables作为系统的防火墙,而是使用了FirewallD,但是为了兼容过去的命令也可以使用iptables来设置防护规则,但启动的时候自搞了一套。

解决方法也很简单。

首先,可以考虑follow官方的想法转用FirewallD。其实查看一些官方文档也能用。 但是,个人觉得若没有显著的提升也可以继续使用原来的iptables。若打算继续使用iptables, 可以继续做如下:

备份当前规则

iptables-save > iptables.rules

禁用FireWallD,安装&启用iptables-services

systemctl stop firewalld
systemctl mask firewalld
yum install iptables-services -y
systemctl enable iptables

这时候检查iptables发现规则被清空了

iptables -L -x -n

将备份的规则还原

iptables-restore iptables.rules

保存当前规则

/usr/libexec/iptables/iptables.init save

若使用minimize版本的安装,可能会出现提示

iptables: Saving firewall rules to /etc/sysconfig/iptables: /etc/init.d/iptables: line 274: restorecon: command not found

这是因为selinux没有安装的缘故,缺少一个组件。安装policycoreutils即可。

yum install policycoreutils -y

References :

Categories: Code

Yu

Ideals are like the stars: we never reach them, but like the mariners of the sea, we chart our course by them.

5 Comments

xqiushi · June 29, 2016 at 21:31

Safari 9.1.1 Safari 9.1.1 Mac OS X  10.11.5 Mac OS X 10.11.5

我放了一个图床程序在本地服务器上,已按照这时原相关设置了,访问还很慢。可能是程序的问题吧。谢谢

    yu · June 30, 2016 at 12:28

    Google Chrome 51.0.2704.103 Google Chrome 51.0.2704.103 Mac OS X  10.11.5 Mac OS X 10.11.5

    @xqiushi 很高兴能对你有用。

    yu · July 1, 2016 at 14:10

    Google Chrome 51.0.2704.103 Google Chrome 51.0.2704.103 Mac OS X  10.11.5 Mac OS X 10.11.5

    @xqiushi 另外,速度和 iptables 恐怕关系不大,若 iptables 设错了,一般是直接丢包的..

      xqiushi · July 1, 2016 at 14:13

      Google Chrome 51.0.2704.106 Google Chrome 51.0.2704.106 Windows 8.1 x64 Edition Windows 8.1 x64 Edition

      @yu
      谢谢,应该是图床程序语言的问题哈。

日进斗金 · May 17, 2016 at 08:18

Google Chrome 50.0.2661.102 Google Chrome 50.0.2661.102 Windows 10 x64 Edition Windows 10 x64 Edition

感谢您为我解疑答惑!

Leave a Reply to xqiushi Cancel reply

Your email address will not be published. Required fields are marked *