Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
guanyin9cn
V2EX  ›  Linux

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

  •  
  •   guanyin9cn · Sep 14, 2021 · 1399 views
    This topic created in 1723 days ago, the information mentioned may be changed or developed.

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

    用 iptables 当然会很慢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5905 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 93c8b4a0 · 33ms · UTC 06:28 · PVG 14:28 · LAX 23:28 · JFK 02:28
    ♥ Do have faith in what you're doing.