V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
guanyin9cn
V2EX  ›  Linux

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

  •  
  •   guanyin9cn · 2021-09-14 14:25:40 +08:00 · 309 次点击
    这是一个创建于 926 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 表记录太多导致的问题?

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

    用 iptables 当然会很慢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1188 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 23:19 · PVG 07:19 · LAX 16:19 · JFK 19:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.