清除剩余的 firewalld 规则

  1. 如果需要,我们可以使用以下命令清除 firewalld 遗留的 iptables 规则。
# iptables -t nat -F
# iptables -t mangle -F
# iptables -F
# iptables -X
# service iptables save
  1. 运行上述命令后,我们将获得一个空的 iptable 规则,如下所示。
# 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
如何在 CentOS/RHEL 7 中禁用 firewalld 并切换到 iptables

默认情况下,RHEL 7 使用 FirewallD 服务来提供网络安全。
Firewalld 可能不是每个人都喜欢的,我们可能更喜欢 iptables。
使用 iptables 服务时必须停止并禁用 FirewallD。
这些帖子概述了在 CentOS/RHEL 7 中禁用 firewalld 和启用 iptables 的步骤。

停止并禁用 firewalld

  1. 首先,我们应该禁用 Firewalld 并确保它不会在启动时再次启动。
# systemctl stop firewalld
# systemctl disable firewalld
  1. 屏蔽 firewalld 服务会创建一个从 /etc/systemd/system/firewalld.service 到 /dev/null 的符号链接,从而禁用 firewalld 服务。
# systemctl mask firewalld
Created symlink from /etc/systemd/system/firewalld.service to /dev/null.
on  It Road.com

安装和配置 iptables

  1. 要启用iptables,首先我们必须安装“iptables-services”包。
# yum install iptables-services
  1. 启动并启用iptables 服务,以便在启动时自动启用。
# systemctl start iptables
# systemctl enable iptables

检查firewalld是否遗留了任何规则。
默认情况下,新安装的 iptables 将具有如下所示的 iptables 规则。

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
日期:2020-09-17 00:13:30 来源:oir作者:oir