Skip to content
Eternal Center

Eternal Center

  • Single-Node (单节点)
    • System (系统)
    • Service (服务)
    • Database (数据库)
    • Container (容器)
    • Virtualization (虚拟化)
  • Multi-Node (多节点)
    • Cluster (集群)
    • Big Data (大数据)
    • Cloud Computing (云计算)
    • Batch Processing (批量处理)
  • Approach (方式方法)
    • Languages (语言)
    • Ideas (思路)
    • Programing (编程)
    • Project (项目)
  • Eternity (永恒)
    • News (消息)
    • Creations (创作)
    • Classics (经典)
    • Legends (传说)
    • Chronicle (编年史)
    • FNIOS (宇宙公民开源学院)
Posted on August 3, 2021October 19, 2022 by Mingyu Zhu

[步骤] nftables 防火墙的使用 (永久版)

注意:

只有 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 防火墙策略
      • 2.3 让添加的 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 中添加的
)

2.3 让添加的 nftables 防火墙策略生效

# systemctl start nftables

补充:

nftables 防火墙策略文件的常用规则
CategoriesChinese Post (中文帖子), nftables, System (系统), System Firewall (系统防火墙), System Login Security (系统登录安全), System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志), System Port Security (系统端口安全), System Security (系统安全)

Post navigation

Previous PostPrevious [步骤] nftables 防火墙的使用 (临时版)
Next PostNext [命令] Linux 命令 system-analyze (显示服务启动时间)

Aspiration (愿景):

Everyone can achieve self-achievement and self-happiness fairly

每个人都能公平地实现自我成就和自我幸福

Logo (徽标):

Additional Information (其他信息):

About     Manual     Clone     Contact
Disclaimer     Friendly Links     Donation

关于     手册     克隆     联系
免责声明     友情链接     捐赠

Search Inside Website (站内搜索)

Search Outside Website (站外搜索):

Google         Wikipedia         Bing

Eternal URL (永恒网址):

https://eternity.eternalcenter.com Will be last access method / 将是最后的访问方式

Proudly powered by LNMP Proudly powered by WordPress