注意:
只有 CentOS 8 & RHEL 8 才可以使用 nftables 防火墙
正文:
步骤目录:
步骤一:从 firewalld 防火墙切换至 nftables 防火墙
1.1 安装 nftables 防火墙
1.2 清空 iptables 防火墙的策略表
1.2.1 清空 ipv4 iptables 防火墙的策略表
1.2.2 清空 ipv6 iptables 防火墙的策略表
1.3 停止使用 firewalld 防火墙
1.3.1 取消 firewalld 防火墙开机自启
1.3.2 停止 firewalld 防火墙
1.4 启用 nftables 防火墙
1.4.1 开机自启 nftables 防火墙
1.4.2 启动 nftables 防火墙
步骤二:创建永久的 nftales 防火墙的策略表并条件永久的 nftables 防火墙策略
2.1 在 nftables 防火墙的配置文件中添加 nftables 防火墙策略文件
2.2 在 nftables 防火墙策略文件中添加 nftables 防火墙策略
具体的操作步骤:
步骤一:从 firewalld 防火墙切换至 nftables 防火墙
1.1 安装 nftables 防火墙
# dnf install nftables
1.2 清空 iptables 防火墙的策略表
1.2.1 清空 ipv4 iptables 防火墙的策略表
# iptables -F
1.2.2 清空 ipv6 iptables 防火墙的策略表
# ip6tables -F
1.3 停止使用 firewalld 防火墙
1.3.1 取消 firewalld 防火墙开机自启
# systemctl disable firewalld.service
1.3.2 停止 firewalld 防火墙
# systemctl stop firewalld.service
1.4 启用 nftables 防火墙
1.4.1 开机自启 nftables 防火墙
# systemctl enable nftables
1.4.2 启动 nftables 防火墙
# systemctl start nftables
步骤二:创建永久的 nftales 防火墙的策略表并条件永久的 nftables 防火墙策略
2.1 在 nftables 防火墙的配置文件中添加 nftables 防火墙策略文件
# vi /etc/sysconfig/nftables.conf
添加以下内容:
......
include "/etc/nftables/nftables.rules"
2.2 在 nftables 防火墙策略文件中添加 nftables 防火墙策略
# vi /etc/nftables/nftables.rules
flush ruleset
table inet siemens_FW {
chain siemens_FW_input {
type filter hook input priority 0; policy accept;
iif "lo" accept
ip saddr 127.0.0.0/8 counter packets 0 bytes 0 drop
ip6 saddr ::1 counter packets 0 bytes 0 drop
ip saddr 192.168.1.1 tcp dport ssh accept
tcp dport ssh drop
}
chain siemens_FW_forward {
type filter hook forward priority 0; policy accept;
}
chain siemens_FW_output {
type filter hook output priority 0; policy accept;
}
}
(
补充:
(1)这里以基本的本地巡回路由策略并禁止除 192.168.1.1 的 IP 地址访问本地的 22 端口为例
(2)这里的 /etc/nftables/nftables.rules 是在 2.1 中添加的
)