1. 首页 > Linux教程 > 正文

Linux教程FG285-nftables框架安装与基础配置

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

本文档风哥主要介绍nftables框架的安装与基础配置方法,包括nftables简介、安装步骤、基本语法、规则配置等内容。

Part01-基础概念与理论知识

1.更多视频教程www.fgedu.net.cn1 nftables简介

# nftables特点
– Linux内核级别的包过滤框架
– 替代iptables、ip6tables、arptables、ebtables
– 统一的语法和接口
– 更好的性能和灵活性

# 核心概念
Table(表):规则的容器
Chain(链):规则的集合
Rule(规则):具体的过滤规则

Part02-生产环境规划与建议

2.1 nftables使用场景

# 使用场景
1. 替代iptables
2. 复杂的包过滤规则
3. 网络地址转换(NAT)
4. 流量统计和监控

Part03-生产环境项目实施方案

3.1 nftables安装

# 安装nftables
$ sudo dnf install nftables -y

# 启动nftables服务
$ sudo systemctl start nftables

# 设置开机自启
$ sudo systemctl enable nftables

# 查看服务状态
$ sudo systemctl status nftables
● nftables.service – Netfilter Tables
Loaded: loaded (/usr/lib/systemd/system/nftables.service; enabled; vendor preset: disabled)
Active: active (exited) since Mon 2026-04-06 10:00:00 CST; 1h ago

3.2 基本配置

# 查看当前规则
$ sudo nft list ruleset
table inet filter {
chain input {
type filter hook input priority 0;
}
}

# 创建表
$ sudo nft add table inet filter

# 创建链
$ sudo nft add chain inet filter input { type filter hook input priority 0 \; }

# 添加规则
$ sudo nft add rule inet filter input tcp dport 22 accept

# 查看规则
$ sudo nft list table inet filter
table inet filter {
chain input {
type filter hook input priority 0;
tcp dport 22 accept
}
}

Part04-生产案例与实战讲解

4.1 案例:基础防火墙配置

# 创建完整的防火墙规则
$ sudo nft add table inet firewall
$ sudo nft add chain inet firewall input { type filter hook input priority 0 \; policy drop \; }
$ sudo nft add chain inet firewall forward { type filter hook forward priority 0 \; policy drop \; }
$ sudo nft add chain inet firewall output { type filter hook output priority 0 \; policy accept \; }

# 允许SSH连接
$ sudo nft add rule inet firewall input tcp dport 22 accept

# 允许已建立的连接
$ sudo nft add rule inet firewall input ct state established,related accept

# 允许本地回环
$ sudo nft add rule inet firewall input iif lo accept

# 查看规则
$ sudo nft list table inet firewall

风哥提示:

Part05-风哥经验总结与分享

nftables是iptables的继任者,语法更统一,性能更好。建议新环境使用nftables,但要注意与firewalld的兼容性问题。

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息