请教一个关于 sing-box Tun 模式路由的问题 - V2EX
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
AceDogs
V2EX    Linux

请教一个关于 sing-box Tun 模式路由的问题

  •  
  •   AceDogs Apr 5, 2024 4483 views
    This topic created in 767 days ago, the information mentioned may be changed or developed.

    我在 sing-box 中启用 tun 后,路由表如下:

    default via 192.168.2.1 dev eth0 proto dhcp src 192.168.2.17 metric 202 169.254.0.0/16 dev vethba29967 scope link src 169.254.195.244 metric 210 169.254.0.0/16 dev veth49bc574 scope link src 169.254.56.104 metric 212 169.254.0.0/16 dev vethff3d6f6 scope link src 169.254.200.208 metric 214 169.254.0.0/16 dev vethbe3a716 scope link src 169.254.13.45 metric 216 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown 172.19.0.0/30 dev tun0 proto kernel scope link src 172.19.0.1 172.24.0.0/16 dev br-4bea34453033 proto kernel scope link src 172.24.0.1 172.25.0.0/16 dev br-7b558a8ec2e7 proto kernel scope link src 172.25.0.1 172.26.0.0/16 dev br-f645b1779cd6 proto kernel scope link src 172.26.0.1 172.27.0.0/16 dev br-a887ffeba8e3 proto kernel scope link src 172.27.0.1 192.168.2.0/24 dev eth0 proto dhcp scope link src 192.168.2.17 metric 202 

    我怎么都看不懂,为什么 tun0 网卡可以捕获所有的流量,看路由表的意思不是应该只能把目标为 172.19.0.0/30 的数据捕获吗? 操作系统 Ubuntu 22

    14 replies    2024-08-15 17:19:04 +08:00
    chinni
        1
    chinni  
       Apr 5, 2024
    了解下 ip rule 和 ip route list table <table_id>
    AceDogs
        2
    AceDogs  
    OP
       Apr 5, 2024
    iptables 信息如下, 看起来除了 docker 的也没见和这个 tun 有关的。
    ```
    Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
    pkts bytes target prot opt in out source destination

    Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
    pkts bytes target prot opt in out source destination
    3008 1043K DOCKER-USER all -- * * 0.0.0.0/0 0.0.0.0/0
    3008 1043K DOCKER-ISOLATION-STAGE-1 all -- * * 0.0.0.0/0 0.0.0.0/0
    0 0 ACCEPT all -- * docker0 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
    0 0 DOCKER all -- * docker0 0.0.0.0/0 0.0.0.0/0
    0 0 ACCEPT all -- docker0 !docker0 0.0.0.0/0 0.0.0.0/0
    0 0 ACCEPT all -- docker0 docker0 0.0.0.0/0 0.0.0.0/0
    374 346K ACCEPT all -- * br-f645b1779cd6 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
    0 0 DOCKER all -- * br-f645b1779cd6 0.0.0.0/0 0.0.0.0/0
    292 25545 ACCEPT all -- br-f645b1779cd6 !br-f645b1779cd6 0.0.0.0/0 0.0.0.0/0
    0 0 ACCEPT all -- br-f645b1779cd6 br-f645b1779cd6 0.0.0.0/0 0.0.0.0/0
    825 396K ACCEPT all -- * br-a887ffeba8e3 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
    0 0 DOCKER all -- * br-a887ffeba8e3 0.0.0.0/0 0.0.0.0/0
    1485 265K ACCEPT all -- br-a887ffeba8e3 !br-a887ffeba8e3 0.0.0.0/0 0.0.0.0/0
    0 0 ACCEPT all -- br-a887ffeba8e3 br-a887ffeba8e3 0.0.0.0/0 0.0.0.0/0
    17 8109 ACCEPT all -- * br-7b558a8ec2e7 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
    0 0 DOCKER all -- * br-7b558a8ec2e7 0.0.0.0/0 0.0.0.0/0
    15 2313 ACCEPT all -- br-7b558a8ec2e7 !br-7b558a8ec2e7 0.0.0.0/0 0.0.0.0/0
    0 0 ACCEPT all -- br-7b558a8ec2e7 br-7b558a8ec2e7 0.0.0.0/0 0.0.0.0/0
    0 0 ACCEPT all -- * br-4bea34453033 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
    0 0 DOCKER all -- * br-4bea34453033 0.0.0.0/0 0.0.0.0/0
    0 0 ACCEPT all -- br-4bea34453033 !br-4bea34453033 0.0.0.0/0 0.0.0.0/0
    0 0 ACCEPT all -- br-4bea34453033 br-4bea34453033 0.0.0.0/0 0.0.0.0/0

    Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
    pkts bytes target prot opt in out source destination

    Chain DOCKER (5 references)
    pkts bytes target prot opt in out source destination
    0 0 ACCEPT tcp -- !br-a887ffeba8e3 br-a887ffeba8e3 0.0.0.0/0 172.27.0.2 tcp dpt:9091

    Chain DOCKER-ISOLATION-STAGE-1 (1 references)
    pkts bytes target prot opt in out source destination
    0 0 DOCKER-ISOLATION-STAGE-2 all -- docker0 !docker0 0.0.0.0/0 0.0.0.0/0
    292 25545 DOCKER-ISOLATION-STAGE-2 all -- br-f645b1779cd6 !br-f645b1779cd6 0.0.0.0/0 0.0.0.0/0
    1485 265K DOCKER-ISOLATION-STAGE-2 all -- br-a887ffeba8e3 !br-a887ffeba8e3 0.0.0.0/0 0.0.0.0/0
    15 2313 DOCKER-ISOLATION-STAGE-2 all -- br-7b558a8ec2e7 !br-7b558a8ec2e7 0.0.0.0/0 0.0.0.0/0
    0 0 DOCKER-ISOLATION-STAGE-2 all -- br-4bea34453033 !br-4bea34453033 0.0.0.0/0 0.0.0.0/0
    3008 1043K RETURN all -- * * 0.0.0.0/0 0.0.0.0/0

    Chain DOCKER-ISOLATION-STAGE-2 (5 references)
    pkts bytes target prot opt in out source destination
    0 0 DROP all -- * docker0 0.0.0.0/0 0.0.0.0/0
    0 0 DROP all -- * br-f645b1779cd6 0.0.0.0/0 0.0.0.0/0
    0 0 DROP all -- * br-a887ffeba8e3 0.0.0.0/0 0.0.0.0/0
    0 0 DROP all -- * br-7b558a8ec2e7 0.0.0.0/0 0.0.0.0/0
    0 0 DROP all -- * br-4bea34453033 0.0.0.0/0 0.0.0.0/0
    1792 293K RETURN all -- * * 0.0.0.0/0 0.0.0.0/0

    Chain DOCKER-USER (1 references)
    pkts bytes target prot opt in out source destination
    3008 1043K RETURN all -- * * 0.0.0.0/0 0.0.0.0/0
    ```
    yyzh
        3
    yyzh  
       Apr 5, 2024
    DNS 给的 fake-ip 啊
    AceDogs
        4
    AceDogs  
    OP
       Apr 5, 2024
    @yyzh 按照我的理解 fake-ip 要能收到 dns 请求才能生效,也就是先要能拦截 dns 请求。 我即使关闭 fake-ip 功能,这个 tun 依然可以获取所有网络流量。
    seers
        5
    seers  
       Apr 5, 2024
    你的网关是 tun 设备,网关工作在三层
    yyzh
        6
    yyzh  
       Apr 5, 2024
    @AceDogs 你 ip route show table all 和 ip rule list 都跑一下看看?
    SenLief
        7
    SenLief  
       Apr 5, 2024
    你可以关闭 fake-ip 后查看路由表的配置就知道了。他所有的流量都走了 tun0 那个路由的。
    AceDogs
        8
    AceDogs  
    OP
       Apr 5, 2024
    @yyzh 非常感谢,ip route show table all 确实包含了预期的路由表。我去了解一下相关知识。

    pi@miniserver:~ $ ip route show table all
    0.0.0.0/1 dev tun0 table 2022
    128.0.0.0/1 dev tun0 table 2022
    default via 192.168.2.1 dev eth0 proto dhcp src 192.168.2.17 metric 202
    yyzh
        9
    yyzh  
       Apr 5, 2024   1
    AceDogs
        10
    AceDogs  
    OP
       Apr 5, 2024
    @seers 找到原因了,sing-box 配置的路由表不在默认的 main 路由表, 在一个自定义的路由表中,我反复在查看 main 路由表,导致看不到。
    AceDogs
        11
    AceDogs  
    OP
       Apr 5, 2024
    @yyzh 非常感谢,我明白了。
    hefish
        12
    hefish  
       Apr 6, 2024
    得把 dns 指过去把,让 sing-box 把 dns 的解析结果都指到 tun 所在的段,然后这所有流量不就从 tun 走了嘛。。
    garryforreg420
        13
    garryforreg420  
       May 11, 2024
    需要用 "inet4_route_address" 参数自定义路由表,否则默认就是所有流量都进去
    sikeer
        14
    sikeer  
       Aug 15, 2024
    关于这个问题,请教一下,如果 tun 通过路由捕获了几乎所有流量,还用设置系统代理吗?
    "inbounds": [
    {
    "type": "tun",
    "inet4_address": "172.19.0.1/30",
    "mtu": 1500,
    "auto_route": true,
    // "strict_route": true,
    "sniff": true,
    "inet4_route_exclude_address": ["239.255.255.250/32"],
    "sniff_override_destination": false
    "endpoint_independent_nat": false,
    "stack": "system",
    "platform": {
    "http_proxy": {
    "enabled": true,
    "bypass_domain": [],
    "server": "127.0.0.1",
    "server_port": 7890
    }
    }
    },

    {
    "type": "mixed",
    "listen_port": 7890,
    "sniff": true,
    "set_system_proxy": true
    },


    也就是上面的设置中,set_system_proxy 还需要吗
    About     Help     Advertise     Blog     API     FAQ     Solana     3261 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 42ms UTC 12:17 PVG 20:17 LAX 05:17 JFK 08:17
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86