关于 iptables mangle 表 fwmark 标记实现分流 操作中的 RETURN target 问题。

2021-09-14 14:25:40 +08:00
 guanyin9cn

RT, 用 fwmark 做分流操作,

iptables -t mangle -N GFW
iptables -t mangle -F GFW

iptables -t mangle -A GFW -d 0.0.0.0/7 -j RETURN
iptables -t mangle -A GFW -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A GFW -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A GFW -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A GFW -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A GFW -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A GFW -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A GFW -d 240.0.0.0/4 -j RETURN

#此处省略 8 千行
....

#add mark
iptables -t mangle -A GFW -j MARK --set-xmark 0x400

# 追加到  mangle prerouting 链
iptables -t mangle -A PREROUTING -i br0  -j GFW

#route table 400
ip rule add fwmark 0x400 table 400
ip -4 route add 0.0.0.0/0 dev wg0 table 400

实际使用过程中,打开网页很慢。 如果不加 return , 让所有流量都通过 wg0 走,会很快,秒开。 请问 是 mangle 表 对 return 支持度不够,还是 route 表记录太多导致的问题?

363 次点击
所在节点    Linux
6 条回复
hyq
2021-09-14 14:37:39 +08:00
你这个 8000 行,不如试试配合 ipset 使用
guanyin9cn
2021-09-14 14:48:52 +08:00
@hyq 主要是有的设备,比如 hw 光猫,不支持 ipset , 缺少 ipset 内核模块,编译难度巨大无比。只能采用这种取巧的方法。
guanyin9cn
2021-09-14 14:52:11 +08:00
@hyq #1 这是目前找到的,能在 光猫缺少 tproxy.ko, ipset.ko 的情况下,同时代理 tcp 和 udp 的 方法。
hyq
2021-09-14 14:58:17 +08:00
有个精简版的 chnroute,准确度低一点,但是条数很少,可以测试下是不是条目数的问题
https://ikk.me/archives/default/chnroute-mini.html/comment-page-1
guanyin9cn
2021-09-14 15:03:33 +08:00
@hyq 有可能是,晚上回去试试。
第一次 导入比较慢,导入成功后,用 iptables-save -t mangle > gfw-mangle, 保存。
以后用 iptables-save --table=mangle < gfw-mangle,秒导。
CRVV
2021-09-14 16:46:50 +08:00
iptables 是一个 chain,这么写是 O(n) 的复杂度。
路由表是 trie,对数复杂度。

用 iptables 当然会很慢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/801750

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX