OWenT's blog
  • Introduction
  • About Me
  • 2020
    • 近期对libatapp的一些优化调整(增加服务发现和连接管理,支持yaml等)
    • xresloader转表工具链增加了一些新功能(map,oneof支持,输出矩阵,基于模板引擎的加载代码生成等)
    • 在游戏服务器中使用分布式事务
    • libcopp接入C++20 Coroutine和一些过渡期的设计
    • libatbus 的大幅优化
    • nftables初体验
    • 容器配置开发环境小计
  • 2019
    • PALM Tree - 适合多核并发架构的B+树 - 论文阅读小记
    • 跨平台协程库 - libcopp 简介
    • C++20 Coroutine 性能测试 (附带和libcopp/libco/libgo/goroutine/linux ucontext对比)
    • 尝鲜Github Action
    • 一些xresloader(转表工具)的改进
    • protobuf、flatbuffer、msgpack 针对小数据包的简单对比
    • 协程框架(libcopp) 小幅优化
    • Excel转表工具(xresloader) 增加protobuf插件功能和集成 UnrealEngine 支持
    • Anna(支持任意扩展和超高性能的KV数据库系统)阅读笔记
    • C++20 Coroutine
    • libcopp merge boost.context 1.69.0
    • Google去中心化分布式系统论文三件套(Percolator、Spanner、F1)读后感
    • Rust玩具-企业微信机器人通用服务
  • 2018
    • 使用ELK辅助监控开发测试环境服务质量和问题定位
    • Webpack+vue+boostrap+ejs构建Web版GM工具
    • 2018年的新通用伪随机数算法(xoshiro / xoroshiro)的C++(head only)实现
    • Rust的第二次接触-写个小服务器程序
    • 理解和适配AEAD加密套件
    • atsf4g-co的进化:协程框架v2、对象路由系统和一些其他细节优化
    • 协程框架(libcopp)v2优化、自适应栈池和同类库的Benchmark对比
    • 可执行文件压缩
    • 初识Rust
    • 使用restructedtext编写xresloader文档
    • atframework的etcd模块化重构
    • C++的backtrace
  • 2017
    • ECDH椭圆双曲线(比DH快10倍的密钥交换)算法简介和封装
    • protobuf-net的动态Message实现
    • pbc的proto3接入
    • atgateway内置协议流程优化-加密、算法协商和ECDH
    • 整理一波软件源镜像同步工具+DevOps工具
    • Blog切换到Hugo
    • libcopp v2的第一波优化完成
    • libcopp(v2) vs goroutine性能测试
    • libcopp的线程安全、栈池和merge boost.context 1.64.0
    • GCC 7和LLVM+Clang+libc++abi 4.0的构建脚本
    • libatbus的几个藏得很深的bug
    • 用cmake交叉编译到iOS和Android
    • 开源项目得一些小维护
    • atapp的c binding和c#适配
    • 对象路由系统设计
    • 2016年总结
    • 近期的一个协程流程BUG
  • 2016
    • 重写了llvm+clang+libc++和libc++abi的构建脚本
    • atsf4g完整游戏工程示例
    • atframework基本框架已经完成
    • 游戏服务器的不停服更新
    • 对atbus的小数据包的优化
    • Android和IOS的TLS问题
    • pbc的一个陈年老BUG
    • boost.context-1.61版本的设计模型变化
    • 接入letsencrypt+全面启用HTTP/2
    • 理解Raft算法
    • libatbus基本功能及单元测试终于写完啦
    • 博客文章和文档迁移到gitbook
  • 2015
    • 博客文章和文档迁移到gitbook
    • 给客户端写得LRU缓存
    • 近期活动比较零散
    • 关于BUS通信系统的一些思考(三)
    • 针对Java JIT的优化(转表工具:xresloader)
    • libcopp更新 (merge boost 1.59 context)
    • 小记最近踩得两个C++坑
    • Redis全异步(HA)Driver设计稿
    • Vim常用命令
    • 关于firewalld和systemd的一些命令速记
    • Jenkins(hudson)插件记录
    • 我们的Lua类绑定机制
    • LLVM+Clang+Libcxx+Libcxxabi(3.6)工具链编译(完成自举编译)
    • 回顾2014
    • Android NDK undefined reference to ___tls_get_addr 错误
    • gitlab腾讯企业邮箱配置
  • 2014
    • 回顾2013
    • C++11动态模板参数和type_traits
    • C++又一坑:动态链接库中的全局变量
    • tolua++内存释放坑
    • [转]类似github的框架
    • Lua性能分析
    • 集成Qt Webkit 到cocos2d-x
    • Gitlab环境搭建小计
    • 近期研究VPN的一些记录(OpenVPN,pptp,l2tp)
    • LLVM + Clang + Libcxx + Libcxxabi 工具链编译
    • 关于BUS通信系统的一些思考(二)
    • 关于BUS通信系统的一些思考(一)
    • [libiniloader] Project
    • 记录一些在线编辑器
    • [WP Code Highlight.js] Project
    • 再议 C++ 11 Lambda表达式
    • 基于Chrome插件的开发工具链
    • [ACM] HDU 1006 解题报告
    • Linux 编译安装 GCC 4.9
    • 又碰到了这个解谜游戏,顺带记下地址
    • 简单C++单元测试框架(支持一键切到GTest或Boost.Test)
    • 捣鼓一个协程库
  • 2013
    • std和boost的function与bind实现剖析
    • 不知道是哪一年的腾讯马拉松题目 照片评级 解题报告
    • Lua 挺好用的样子
    • VC和GCC成员函数指针实现的研究(三)
    • VC和GCC成员函数指针实现的研究(二)
    • VC和GCC内成员函数指针实现的研究(一)
    • 一个C++关于成员变量偏移地址的小Trick
    • ptmalloc,tcmalloc和jemalloc内存分配策略研究
    • POJ 2192 Zipper HDU 2059 龟兔赛跑
    • 从Javascript到Typescript到Node.js
    • 网络编程小结
    • 试试Boost.Asio
    • Lnmp yum 安装脚本 (for CentOS)
    • ARM 交叉编译环境搭建
    • Linux 编译安装 GCC 4.8
    • [记录]虚拟硬盘的压缩|磁盘写零
  • 2012
    • Boost.Spirit 初体验
    • “C++的90个坑”-阅读笔记
    • AC自动机
    • C++ 标准过渡期
    • 程序员修炼之道 -- 阅读笔记
    • [转载]狼与哈士奇
    • C++ 新特性学习(八) — 原子操作和多线程库[多工内存模型]
    • C++ 新特性学习(七) — 右值引用
    • 理解Protobuf的数据编码规则
    • 忆往昔ECUST的ACM时代
    • Linux编译安装GCC 4.7
    • JSON显示库 -- showJson (Javascript)
    • C++ 新特性学习(六) — 新的字符串编码和伪随机数
    • C++ 新特性学习(五) — 引用包装、元编程的类型属性和计算函数对象返回类型
    • C++ 新特性学习(四) — Bind和Function
  • 2011
    • C++ 新特性学习(三) — Regex库
    • C++ 新特性学习(二) -- Array、Tuple和Hash库
    • C++ 新特性学习(一) -- 概述+智能指针(smart_ptr)
    • Linux 和 Windows PowerShell 常用工具/命令 记录
    • 非常帅气的Linq to sql
    • 2011 Google Code Jam 小记
    • C++总是很神奇
    • 大学生创新项目[国家级]经费使用记录
    • 常用官方文档整理
    • 我们学校的IPV6很不错嘛
  • 2010
    • 线段树相关问题 (引用 PKU POJ题目) 整理
    • 2010 ACM 赛前笔记
    • POJ PKU 2596 Dice Stacking 解题报告
    • POJ PKU 3631 Cuckoo Hashing 解题报告
    • POJ PKU 1065 Wooden Sticks 3636 Nested Dolls 解题报告
    • HDU 3336 Count the string 解题报告
    • Hash模板 个人模板
    • ZOJ 3309 Search New Posts 解题报告
    • POJ PKU Let's Go to the Movies 解题报告
    • 注册表常用键值意义
    • PKU POJ 1724 ROADS 解题报告
    • 《神奇古今秘方集锦》&《民间秘术大全》
    • PKU POJ 1720 SQUARES 解题报告
    • POJ PKU 2155 Matrix 解题报告
    • PKU POJ 1141 Brackets Sequence 解题报告
    • PKU POJ 2728 Desert King 解题报告
    • PKU POJ 2976 Dropping tests 解题报告
    • PKU POJ 3757 Simple Distributed storage system 解题报告
    • GCD Determinant 解题报告
    • Southeastern European 2008 Sky Code 解题报告
    • HDU HDOJ 3400 Line belt 解题报告
    • 线性筛法求质数(素数)表 及其原理
    • HDU HDOJ 3398 String 解题报告
    • 树状数组模块(个人模板)
    • 浙江理工 省赛总结 team62 By OWenT of Coeus
    • POJ PKU 3659 Cell Phone Network 解题报告
    • USACO 2008 March Gold Cow Jogging 解题报告
    • C#格式化输出(记录)
    • 参加有道难题笔记
    • POJ PKU 2446 Chessboard 解题报告
    • POJ PKU 1986 Distance Queries 解题报告
    • 计算几何算法概览[转载]
    • 关于差分约束(转载)
    • POJ PKU 2826 An Easy Problem?! 解题报告
    • 数论模板(个人模板)
    • 简易四则运算(ACM个人模板)
    • Catalan 数
    • The 35th ACM/ICPC Asia Regional Tianjin Site —— Online Contest 1009 Convex 解题报告
    • JQuery扩展插件--提示信息
    • ACM 计算几何 个人模板
    • 解析网站字符串型参数 Javascript QueryString 操作 TQueryString类
    • POJ PKU 1474 Video Surveillance 解题报告
  • 2009
    • 模式匹配(kmp)个人模板
    • 并查集 模板
    • POJ 3267 The Cow Lexicon 解题报告
    • C/C++语言常用排序算法
    • POJ 2606 Rabbit hunt 2780 Linearity 1118 Lining Up 解题报告
    • 打造最快的Hash表(转) [以暴雪的游戏的Hash为例]
    • ECUST 09年 校赛个人赛第六,七场总结
    • ECUST 09年 校赛个人赛第三场部分解题报告(A,D,F,I)
    • 牛顿迭代解方程 ax^3+bX^2+cx+d=0
    • 09年8月9日 ECUST ACM 练习赛总结
    • 连接最多点直线 (OWenT 个人模板)
    • 点到直线距离 和 线段间最短距离 (OWenT 模板)
    • ECUST 09年 校赛个人训练赛第五场总结
    • ECUST 09年 校赛个人赛第八场(最后一场)总结
    • 09年8月14日 ECUST ACM 练习赛总结
    • 矩阵相关 (增强中)
    • Prime最小生成树(个人模板)
    • 最长单调子序列 复杂度nlog(n)
    • POJ PKU 2549 Sumsets 解题报告
    • POJ PKU 3277 City Horizon 解题报告
    • 我的ACM生涯
    • POJ PKU 2528 Mayor's posters 解题报告
    • POJ PKU 2378 Tree Cutting 解题报告
    • POJ PKU 1990 MooFest 解题报告
Powered by GitBook
On this page
  • 前言
  • nftables与iptables
  • nftables与ebtables
  • nftables与ipset
  • nftables与iptables与NAT
  • nftables与firewalld
  • 备注小记
  • nftables Hook
  • Standard priority names, family and hook compatibility matrix
  • Standard priority names and hook compatibility for the bridge family

Was this helpful?

  1. 2020

nftables初体验

Previouslibatbus 的大幅优化Next容器配置开发环境小计

Last updated 5 years ago

Was this helpful?

前言

之前耳闻 是下一代 。前段时间配了一台主机,折腾成家里的软路由。就一并来尝鲜一系列新东西,其中就包括 。 和 、 等一样,都是对底层 xtables 的封装,目前看来 比 更简洁易用,更易读,更容易理解,扩展性和也更好。但是目前各个发行版中对 的支持还比较参差不齐,导致 很多功能比 还是有所缺失,所以个人感觉短期内还是替代不了 (比如 tproxy 功能需要 linux kernel 4.19+, 而即便是 的内核版本也只是 4.18 ,所以都不支持 )。 所支持的功能列表及所以来的内核版本和内核模块可以在这里找到 。

的功能分两块,一块是内核支持,这个受限于内核版本。另一部分是用户空间的库和工具。有些发行版会滚动更新内核,但是 版本比较低,这时候如果要用就得自己编译。 依赖库及命令行工具的代码仓库如下:

  • libmnl:

  • libnftnl:

  • nftables:

和 一样, 的高版本对依赖库的版本也有一定要求,系统自带的不一定符合要求,就得一个一个编译。我写了一个构建脚本: , 并且实测如果使用 或者 的话,可以宿主机编译,然后mount共享给子机也是可以的。

官方Wiki: 官方文档: 官方文档不是很全,这个文档更完整一些:

nftables与iptables

先贴一张 的流程图。

以下是一些常用命令:

说明

iptables -t mangle -L

nft list table mangle

显示指定table(mangle)的所有chains

-

nft list ruleset

显示所有table的所有chains

iptables -t mangle -A V2RAY -j TRACE

nft add rule inet mangle V2RAY meta nftrace set 1

跟踪调试包

iptables -t mangle -A V2RAY -j LOG --log-level debug --log-prefix "###LOG PREFIX:"

nft add rule inet mangle V2RAY log prefix '"###LOG PREFIX:"' level debug flags all

输出内核日志

nftables与ebtables

另外如果要使用网桥包转路由,然后走比如tproxy需要增加如下配置:

echo "
net.ipv4.ip_forward=1
net.ipv4.ip_forward_use_pmtu=1
net.ipv4.conf.all.forwarding=1
net.ipv4.conf.default.forwarding=1
net.ipv6.conf.all.forwarding=1
net.ipv6.conf.default.forwarding=1
# Configures below are used to support tproxy for bridge
net.bridge.bridge-nf-call-arptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.all.route_localnet=1
net.ipv4.conf.default.route_localnet=1
" > /etc/sysctl.d/91-forwarding.conf ;
sysctl -p ;

nftables与ipset

部分参考对比如下:

ipset create V2RAY_BLACKLIST_IPV4 hash:ip family inet

nft add set ip v2ray BLACKLIST { type ipv4_addr\; }

ipset flush V2RAY_BLACKLIST_IPV4

nft flush set ip v2ray BLACKLIST

ipset add V2RAY_BLACKLIST_IPV4 $PPP_OUTER_IP

nft add element ip v2ray BLACKLIST { $PPP_OUTER_IP } ;

iptables -t mangle -A V2RAY -p tcp -m set --match-set V2RAY_BLACKLIST_IPV4 dst -j RETURN

nft add rule ip v2ray PREROUTING meta l4proto tcp ip daddr @BLACKLIST return

ipset create myset hash:ip,port,ip family inet

nft add set inet filter myset { type type ipv4_addr . inet_service . ipv4_addr : verdict \; }

ipset add myset 172.16.0.1,tcp:80,10.0.0.1

nft add element inet filter myset { 172.16.0.1 . 80 . 10.0.0.1 : accept } ;

iptables -t filter -A INPUT -m set --match-set myset src,dst,dst -j ACCEPT

nft add rule inet filter INPUT meta nfproto ipv4 ip saddr . tcp dport . ip daddr vmap @myset

nftables与iptables与NAT

echo "## Do not load the iptable_nat,ip_tables,ip6table_nat,ip6_tables module on boot.
blacklist iptable_nat
blacklist ip6table_nat

# Upper script will disable auto load , or using scripts below to force disable modules
# install iptable_nat /bin/true
# install ip6table_nat /bin/true
" | tee /etc/modprobe.d/disable-iptables.conf

另外我本地为了支持NAT和一些辅助功能开启的模块如下:

echo "
xt_nat
nf_reject_ipv4
nf_reject_ipv6
nf_tables_set
nf_log_ipv6
nf_log_ipv4
nf_log_common
nf_tables
nfnetlink
nf_nat
nf_conntrack
nf_defrag_ipv6
nf_defrag_ipv4
nft_log
nft_masq
nft_ct
nft_meta_bridge
nft_counter
nft_reject
nft_reject_inet
nft_reject_bridge
nft_chain_nat
nft_nat
" | tee /etc/modules-load.d/nftables-nat.conf

nftables与firewalld

nft list table inet security_firewall > /dev/null 2>&1 ;
if [ $? -eq 0 ]; then
    nft delete table inet security_firewall ;
fi
nft add table inet security_firewall ;

nft add table inet security_firewall ;

nft add chain inet security_firewall PREROUTING { type filter hook prerouting priority raw + 10\; policy accept\; }
nft add rule inet security_firewall PREROUTING icmpv6 type { nd-router-advert, nd-neighbor-solicit } accept ;
nft add rule inet security_firewall PREROUTING meta nfproto ipv6 fib saddr . iif oif missing drop ;

nft add chain inet security_firewall INPUT { type filter hook input priority filter + 10\; policy accept\; }
nft add rule inet security_firewall INPUT ct state { established, related } accept
nft add rule inet security_firewall INPUT ct status dnat accept
# 这里 br0是我自己建的用于内网通信的桥接,添加了enp1s0f0和enp1s0f1 。 enp5s0是我用来调试的接口, WAN口的出口留了两个用于拨号, enp1s0f2 和 enp1s0f3
nft add rule inet security_firewall INPUT iifname { lo, br0, enp1s0f0, enp1s0f1, enp5s0 } accept
# Internal services -- begin
nft add rule inet security_firewall INPUT ip saddr {127.0.0.1/32, 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8} tcp dport 22 ct state { new, untracked } accept
nft add rule inet security_firewall INPUT ip6 saddr {::1/128, fc00::/7, fe80::/10, fd00::/8, ff00::/8} tcp dport 22 ct state { new, untracked } accept
nft add rule inet security_firewall INPUT ip6 daddr fe80::/64 udp dport 546 ct state { new, untracked } accept
nft add rule inet security_firewall INPUT tcp dport 53 ct state { new, untracked } accept
nft add rule inet security_firewall INPUT udp dport 53 ct state { new, untracked } accept
nft add rule inet security_firewall INPUT udp dport 67 ct state { new, untracked } accept
nft add rule inet security_firewall INPUT udp dport 547 ct state { new, untracked } accept
nft add rule inet security_firewall INPUT tcp dport 853 ct state { new, untracked } accept
# 其他自定义要放过的服务端口和协议
# Internal services -- end
nft add rule inet security_firewall INPUT meta l4proto { icmp, ipv6-icmp } accept
nft add rule inet security_firewall INPUT ct state { invalid } drop
nft add rule inet security_firewall INPUT reject with icmpx type admin-prohibited

nft add chain inet security_firewall OUTPUT { type filter hook output priority filter + 10\; policy accept\; }
nft add rule inet security_firewall OUTPUT  oifname "lo" accept
nft add rule inet security_firewall OUTPUT  ip6 daddr { ::/96, ::ffff:0.0.0.0/96, 2002::/24, 2002:a00::/24, 2002:7f00::/24, 2002:a9fe::/32, 2002:ac10::/28, 2002:c0a8::/32, 2002:e000::/19 } reject with icmpv6 type addr-unreachable

nft add chain inet security_firewall FORWARD { type filter hook forward priority filter + 10\; policy accept\; }
nft add rule inet security_firewall FORWARD  ct state { established, related } accept
nft add rule inet security_firewall FORWARD  ct status dnat accept
# 这里 br0是我自己建的用于内网通信的桥接,添加了enp1s0f0和enp1s0f1 。 enp5s0是我用来调试的接口, WAN口的出口留了两个用于拨号, enp1s0f2 和 enp1s0f3
nft add rule inet security_firewall FORWARD  iifname { lo, br0, enp1s0f0, enp1s0f1, enp5s0 } accept
nft add rule inet security_firewall FORWARD  ip6 daddr { ::/96, ::ffff:0.0.0.0/96, 2002::/24, 2002:a00::/24, 2002:7f00::/24, 2002:a9fe::/32, 2002:ac10::/28, 2002:c0a8::/32, 2002:e000::/19 } reject with icmpv6 type addr-unreachable
#
nft add rule inet security_firewall FORWARD  meta l4proto { icmp, ipv6-icmp } accept
nft add rule inet security_firewall FORWARD  ct state { new, untracked } accept
#
nft add rule inet security_firewall FORWARD  ct state { invalid } drop
nft add rule inet security_firewall FORWARD  reject with icmpx type admin-prohibited

备注小记

  • 要使用 tproxy (透明代理) 需要开启的内核模块: (其中 nft_tproxy 要求 linux kernel 4.19+) >

    echo "
    nf_tproxy_ipv4
    nf_tproxy_ipv6
    nf_socket_ipv4
    nf_socket_ipv6
    xt_TPROXY
    nft_socket
    nft_tproxy
    " | tee /etc/modules-load.d/nftables-tproxy.conf

nftables Hook

Type

Families

Hooks

Description

filter

all

all

Standard chain type to use in doubt.

nat

ip, ip6, inet

prerouting, input, output, postrouting

Chains of this type perform Native Address Translation based on conntrack entries. Only the first packet of a connection actually traverses this chain - its rules usually define details of the created conntrack entry (NAT statements for instance).

route

ip, ip6

output

If a packet has traversed a chain of this type and is about to be accepted, a new route lookup is performed if relevant parts of the IP header have changed. This allows to e.g. implement policy routing selectors in nftables.

Standard priority names, family and hook compatibility matrix

The priority parameter accepts a signed integer value or a standard priority name which specifies the order in which chains with same hook value are traversed. The ordering is ascending, i.e. lower priority values have precedence over higher ones.

Name

Value

Families

Hooks

raw

-300

ip, ip6, inet

all

mangle

-150

ip, ip6, inet

all

dstnat

-100

ip, ip6, inet

prerouting

filter

0

ip, ip6, inet, arp, netdev

all

security

50

ip, ip6, inet

all

srcnat

100

ip, ip6, inet

postrouting

Standard priority names and hook compatibility for the bridge family

Name

Value

Hooks

dstnat

-300

prerouting

filter

-200

all

out

100

output

srcnat

300

postrouting

在这张图表示的流程里 比 最大的一个区别就是, 可以自由创建多个 table, 然后去hook图里的不同阶段( )。而 仅有默认的 raw , mangle , nat , filter 等table, hook了名字一样的阶段。 可以建立多个 table, 多个table的执行顺序是按优先级来的( 下面的 Table 6. 和 Table 7. 里有文档)。 其他的规则和流程 和 是一样的。只是 更简单易读一些。

的基本命令表达式为 nft create/add/delete/list/flush table/chain/rule [ip/ip6/inet/arp/bridge/netdev] [表达式] 。其中 inet 相当于 ip+ip6 。

表达式主要有两大类,一类是匹配表达式,还有一类是行为表达式,每一类都分很多种而且是多层级的和 也差不多。但是 有个比较方便的地方是表达式的最后一个参数如果要多个的话,可以用 { VALUE1, VAULE2 } 来一次写多个。比如我要同时匹配 tcp和udp 协议,可以写成 meta l4proto { tcp, udp } ; 如果我要匹配所有的 ipv6 的源地址是私有地址和回环地址的话可以写成 ip6 saddr {::1/128, fc00::/7, fe80::/10, fd00::/8, ff00::/8} 。

上面跟踪调试包流程的时候 可以用 nft monitor trace 来查看包的状态流转。具体可参见 Wiki:

在 里有个工具 iptables-nft (iptables-translate [iptables参数列表]) 可以用来转换 表达式到 表达式。但是我自己实测的不是很全有些地方也有些谬误。

上面的流程图显示来自于桥接的走了另一套状态流转的流程。要控制桥接的流程,传统的做法可以使用 。按文档的说法 ( ), 在 BROUTE 链DROP掉包,能阻止桥接来的包走转发规则,从而转走路由规则。 但是在 的文档里仅有 里写了个例子改路由。然而我尝试了几次并没有成功。不管我怎么设置,最终还是走了桥接的包转发,并没有走我指定的流转路径(比如转换成tproxy)。另外还看到个文档 ( ) 目前还不支持对 BROUTE 的HOOK。所以我自己这里目前还是走的用 。

个人感觉 使用起来比 麻烦一些,很多插件功能不支持,有些规则也有些限制,比如不支持 。但是凑合着还算能用吧。

使用 需要开启内核模块: br_netfilter

我看了一圈文档,没有找到 直接访问 的方式。按Wiki的说法( ) 是可以用 内置的set和map功能来代替。不过现有的一些工具之集成了对 的支持没有支持 的set和map的话,就得另想办法了。

总体上 和 的map和set功能差不太多,有一个区别是 的map和set都是绑在 的table里的,而 没有table的概念。个人觉得 的更好用一些。

按 Wiki 里的说法 ( ) 。要使用 来做 NAT 就要关闭 的NAT。即不能载入 iptable_nat 和 ip6table_nat 。但是我自己这边使用的时候,这两个模块被其他的模块拉起了,也是能正常NAT的。不过我并没有用 配置任何NAT规则。要彻底屏蔽这两个内核模块并且禁止其他模块拉起可以运行如下脚本:

我之前一直有用 来操作防火墙。但是当把 的后端设为 以后。我发现我自己加的规则老被它刷掉。所以最后我关掉了 并且抄了一份它的默认配置如下:

以下纪录一下我折腾 的过程中留下的一些可以复用的脚本和趟的坑。

NAT的设置脚本:

防火墙设置脚本:

pppoe自动加入和的set的设置脚本:

要使用 tproxy (透明代理) 和打 的设置脚本:

/ 里如果要使用 tproxy (透明代理) 和打 ,需要基于 权限

要管理 的 broute 链要开启内核模块: br_netfilter

nftables
iptables
nftables
https://www.mankier.com/8/nft#Chains
iptables
nftables
https://www.mankier.com/8/nft#Chains
nftables
iptables
nftables
nftables
iptables
nftables
nftables
https://wiki.nftables.org/wiki-nftables/index.php/Ruleset_debug/tracing
nftables
iptables
nftables
ebtables
https://www.mankier.com/8/ebtables-legacy#Description-Tables
nftables
https://www.mankier.com/8/nft#Statements-Payload_Statement
https://www.mankier.com/8/ebtables-nft
nftables
ebtables
ebtables
iptables
ipset
ebtables
nftables
ipset
https://wiki.nftables.org/wiki-nftables/index.php/Moving_from_ipset_to_nftables
nftables
ipset
nftables
ipset
nftables
nftables
nftables
ipset
nftables
https://wiki.nftables.org/wiki-nftables/index.php/Performing_Network_Address_Translation_(NAT)#Incompatibilities
nftables
iptables
iptables
firewalld
firewalld
nftables
firewalld
nftables
https://github.com/owent-utils/docker-setup/blob/master/setup-router/ppp-nat/setup-nat-ssh.sh
https://github.com/owent-utils/docker-setup/blob/master/setup-router/ppp-nat/setup-nft-security.sh
ipset
nftables
https://github.com/owent-utils/docker-setup/blob/master/setup-router/ppp-nat/setup-ppp-route-ipv4.sh
SO_MARK
https://github.com/owent-utils/docker-setup/blob/master/setup-router/v2ray/setup-tproxy.nft.sh
docker
podman
SO_MARK
CAP_NET_ADMIN
ebtables
iptables
nftables
ipset
nftables
nftables
iptables
nftables
nftables
iptables
ebtables
nftables
iptables
nftables
nftables
iptables
iptables
CentOS 8
nftables
https://wiki.nftables.org/wiki-nftables/index.php/Supported_features_compared_to_xtables
nftables
nftables
nftables
http://git.netfilter.org/libmnl/
http://git.netfilter.org/libnftnl/
http://git.netfilter.org/nftables/
podman
nftables
https://github.com/owent-utils/docker-setup/blob/master/build-nftables.sh
podman
docker
https://wiki.nftables.org
https://www.netfilter.org/projects/nftables/manpage.html
https://www.mankier.com/8/nft
iptables
2002-nf-packet-flow.svg