iptables 应该这么长吗?许多链?

fiz*_*ink 1 iptables

好的,这是 CentOs 7 的全新安装(最小)。

这是iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD_IN_ZONES (0 references)
target     prot opt source               destination         

Chain FORWARD_IN_ZONES_SOURCE (0 references)
target     prot opt source               destination         

Chain FORWARD_OUT_ZONES (0 references)
target     prot opt source               destination         

Chain FORWARD_OUT_ZONES_SOURCE (0 references)
target     prot opt source               destination         

Chain FORWARD_direct (0 references)
target     prot opt source               destination         

Chain FWDI_public (0 references)
target     prot opt source               destination         

Chain FWDI_public_allow (0 references)
target     prot opt source               destination         

Chain FWDI_public_deny (0 references)
target     prot opt source               destination         

Chain FWDI_public_log (0 references)
target     prot opt source               destination         

Chain FWDO_public (0 references)
target     prot opt source               destination         

Chain FWDO_public_allow (0 references)
target     prot opt source               destination         

Chain FWDO_public_deny (0 references)
target     prot opt source               destination         

Chain FWDO_public_log (0 references)
target     prot opt source               destination         

Chain INPUT_ZONES (0 references)
target     prot opt source               destination         

Chain INPUT_ZONES_SOURCE (0 references)
target     prot opt source               destination         

Chain INPUT_direct (0 references)
target     prot opt source               destination         

Chain IN_public (0 references)
target     prot opt source               destination         

Chain IN_public_allow (0 references)
target     prot opt source               destination         

Chain IN_public_deny (0 references)
target     prot opt source               destination         

Chain IN_public_log (0 references)
target     prot opt source               destination         

Chain OUTPUT_direct (0 references)
target     prot opt source               destination  
Run Code Online (Sandbox Code Playgroud)

我的印象是应该只有一个 INPUT、FORWARD 和 OUTPUT 链(至少我在 CentOs 6 机器上是这样的)。

我怎样才能删除其他所有内容?

HBr*_*ijn 6

有少量默认链是 netfilter 核心的一部分:INPUT、FORWARD 和 OUTPUT,但您或通常您的工具可以自由创建额外的链来构建您的防火墙配置。

您看到的是新的,没有错的防火墙配置工具的结果firewalld(其他工具如Shorewall也可能创建任意数量的附加链)。

在不了解创建它们的原因的情况下删除这些额外的链可能是徒劳的,或者现在或将来可能会破坏事物。使用 RHEL/CentOS 7,您应该使用firewall-cmd而不是手动编辑/etc/sysconfig/iptables.

您感到气馁,但仍然可以恢复到 Enterprise Linux 6 和更旧的防火墙配置管理方式,并使用 iptables 和 ip6tables 服务而不是 firewalld。

首先通过以 root 身份运行以下命令来禁用 firewalld:

systemctl disable firewalld
systemctl stop firewalld
Run Code Online (Sandbox Code Playgroud)

然后以 root 身份输入以下命令来安装 iptables-services 包:

yum install iptables-services
Run Code Online (Sandbox Code Playgroud)

但是要回答您的直接问题:管理链有据可查

创建新链:使用-N--new-chain选项:

iptables -N test
Run Code Online (Sandbox Code Playgroud)

删除链:删除链也很简单,使用-X--delete-chain选项。为什么-X?好吧,所有的好信都被拿走了。

iptables -X test
Run Code Online (Sandbox Code Playgroud)

删除链有几个限制:它们必须是空的(参见下面的 Flushing a Chain)并且它们不能是任何规则的目标。您不能删除三个内置链中的任何一个。

刷新链:有一种简单的方法可以使用-F(或--flush) 命令从链中清空所有规则。

iptables -F test
Run Code Online (Sandbox Code Playgroud)