tl; dr如何将iptables保留在Centos 7上?
根据Centos 5文档,当服务重新启动或停止时,我应该能够保留我的iptables。我可以确认曾经是这种情况,如果我没记错的话,那是早在Centos 7上的情况。
现在,除非手动调用该service iptables save
命令,否则我将无法保存任何iptables更改。
但是,由于我确实想保存计数器(即使用情况),因此我需要确保重新启动能够持久保存最新的计数器。
我的/etc/sysconfig/iptables-config
样子是这样的:
IPTABLES_MODULES=""
IPTABLES_MODULES_UNLOAD="yes"
IPTABLES_SAVE_ON_STOP="yes"
IPTABLES_SAVE_ON_RESTART="yes"
IPTABLES_SAVE_COUNTER="yes"
IPTABLES_STATUS_NUMERIC="yes"
IPTABLES_STATUS_VERBOSE="no"
IPTABLES_STATUS_LINENUMBERS="yes"
我用: yum info iptables iptables-services xtables-addons
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.coreix.net
* epel: epel.mirror.wearetriple.com
* extras: mirrors.coreix.net
* updates: mirrors.coreix.net
Installed Packages
Name : iptables
Arch : x86_64
Version : 1.4.21
Release : 18.0.1.el7.centos
Size : 1.5 M
Repo : installed
From repo : base
Summary : Tools for managing Linux kernel packet filtering capabilities
URL : http://www.netfilter.org/
License : GPLv2
Description : The iptables utility controls the network packet filtering code in the
: Linux kernel. If you need to set up firewalls and/or IP masquerading,
: you should install this package.
Name : iptables-services
Arch : x86_64
Version : 1.4.21
Release : 18.0.1.el7.centos
Size : 25 k
Repo : installed
From repo : base
Summary : iptables and ip6tables services for iptables
URL : http://www.netfilter.org/
License : GPLv2
Description : iptables services for IPv4 and IPv6
:
: This package provides the services iptables and ip6tables that have been split
: out of the base package since they are not active by default anymore.
Name : xtables-addons
Arch : x86_64
Version : 2.12
Release : 1.el7.lux
Size : 294 k
Repo : installed
From repo : lux
Summary : Extensions targets and matches for iptables
URL : http://xtables-addons.sourceforge.net
License : GPLv2 and LGPLv2
Description : Xtables-addons provides extra modules for iptables not present in the kernel,
: and is the successor of patch-o-matic. Extensions includes new targets like
: TEE, TARPIT, CHAOS, or modules like geoip, ipset, and account.
:
: This package provides the userspace libraries for iptables to use extensions
: in the xtables-addons-kmod package. You must also install the
: xtables-addons-kmod package.
更新#1:
我发现iptables-config
文件非常严格,一个空格将其破坏,而错误的空间将使解析器完全忽略它。重新安装并使用原始文件。
现在我面临的问题是相似的。service iptables stop
现在不保存。重启或关闭都不会。
更新2:
第一个问题肯定是iptables-config
文件。删除所有与iptables相关的文件/etc/sysconfig
并重新安装很快就解决了。
但是,由于权限问题,似乎iptables无法保存。
更新#3:
我错过了通常要更改的安全级别。bellow命令禁用高级安全性,并允许我保存在iptables中。
setenforce 0
工作正常!
事实证明,一系列问题导致我的iptables无法保存或无法加载,或者无法保存并加载然后在其上加载其他内容。
根据我的更新,我的主要问题是:
/etc/sysconfig/iptables-config
格式错误/etc/sysconfig/iptables-config
非常严格 多余的空格会破坏命令或导致其完全忽略命令。我重新安装了软件包并编辑了文件(删除后),以确保它是正确的。
IE
service iptables stop
yum -y install iptables iptables-services
rm -rf /etc/sysconfig/ipt*
yum -y reinstall iptables iptables-services
然后编辑文件。
nano /etc/sysconfig/iptables-config
SELinux强制启用,并且不允许进行保存。我通过“停止”service iptables stop
并注意到它将无法保存而看到了这一点service iptables status -l
。然后,setenforce 0
我暂时禁用了SELinux强制,并允许我保存它们。我不建议您将其作为一种解决方案,您可能会找到更好的解决方案(禁用安全行为不是件好事)。
如何永久禁用:
nano /etc/sysconfig/selinux
然后将指令更改SELinux=enforcing
为SELinux=disabled
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句