Skip to content

Eternal Center

  • System (系统)
  • Services (服务)
  • Databases (数据库)
  • Clusters (集群)
  • Big Data (大数据)
  • Cloud Computing (云计算)
  • Languages (语言)
  • Project (项目)
  • Writings (写作)
  • Eternity (永恒)
  • News (消息)
  • Chronicle (编年史)
  • Words (言)
Posted on August 3, 2021April 25, 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 防火墙策略

具体的操作步骤:

步骤一:从 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 中添加的
)

CategoriesChinese (中文), System (系统), System Firewall (系统防火墙), System Login Security (系统登录安全), System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志), System Security (系统安全)

Post navigation

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

Aspiration (愿景):

Everyone can achieve self achievement and self happiness fairly

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

Position (位置):

Running on Evolution Host and DigitalOcean

正在 Evolution Host 和 DigitalOcean 上运行

Logo (徽标):

Additional Information (其他信息):

About Manual Clone Contact Disclaimer Donation Friendly Links 关于 说明书 克隆 联系 免责申明 捐赠 友情链接

Standby IP Address (备用 IP 地址):

152.69.204.95  150.230.63.10  Please configure before use / 请先配置再使用

Search Outside Website (站外搜索):

Google Wikipedia Bing
Proudly powered by LNMP Proudly powered by WordPress