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

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

  •  
  •   AceDogs · 24 天前 · 1428 次点击

    我在 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

    12 条回复    2024-04-06 16:40:51 +08:00
    chinni
        1
    chinni  
       24 天前
    了解下 ip rule 和 ip route list table <table_id>
    AceDogs
        2
    AceDogs  
    OP
       24 天前
    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  
       24 天前
    DNS 给的 fake-ip 啊
    AceDogs
        4
    AceDogs  
    OP
       24 天前
    @yyzh 按照我的理解 fake-ip 要能收到 dns 请求才能生效,也就是先要能拦截 dns 请求。 我即使关闭 fake-ip 功能,这个 tun 依然可以获取所有网络流量。
    seers
        5
    seers  
       24 天前
    你的网关是 tun 设备,网关工作在三层
    yyzh
        6
    yyzh  
       24 天前
    @AceDogs 你 ip route show table all 和 ip rule list 都跑一下看看?
    SenLief
        7
    SenLief  
       24 天前
    你可以关闭 fake-ip 后查看路由表的配置就知道了。他所有的流量都走了 tun0 那个路由的。
    AceDogs
        8
    AceDogs  
    OP
       24 天前
    @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  
       24 天前   ❤️ 1
    AceDogs
        10
    AceDogs  
    OP
       24 天前
    @seers 找到原因了,sing-box 配置的路由表不在默认的 main 路由表, 在一个自定义的路由表中,我反复在查看 main 路由表,导致看不到。
    AceDogs
        11
    AceDogs  
    OP
       24 天前
    @yyzh 非常感谢,我明白了。
    hefish
        12
    hefish  
       23 天前
    得把 dns 指过去把,让 sing-box 把 dns 的解析结果都指到 tun 所在的段,然后这所有流量不就从 tun 走了嘛。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1338 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 17:37 · PVG 01:37 · LAX 10:37 · JFK 13:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.