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

40 天前
 AceDogs

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

1603 次点击
所在节点    Linux
13 条回复
chinni
40 天前
了解下 ip rule 和 ip route list table <table_id>
AceDogs
40 天前
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
40 天前
DNS 给的 fake-ip 啊
AceDogs
40 天前
@yyzh 按照我的理解 fake-ip 要能收到 dns 请求才能生效,也就是先要能拦截 dns 请求。 我即使关闭 fake-ip 功能,这个 tun 依然可以获取所有网络流量。
seers
40 天前
你的网关是 tun 设备,网关工作在三层
yyzh
40 天前
@AceDogs 你 ip route show table all 和 ip rule list 都跑一下看看?
SenLief
40 天前
你可以关闭 fake-ip 后查看路由表的配置就知道了。他所有的流量都走了 tun0 那个路由的。
AceDogs
40 天前
@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
40 天前
AceDogs
40 天前
@seers 找到原因了,sing-box 配置的路由表不在默认的 main 路由表, 在一个自定义的路由表中,我反复在查看 main 路由表,导致看不到。
AceDogs
40 天前
@yyzh 非常感谢,我明白了。
hefish
40 天前
得把 dns 指过去把,让 sing-box 把 dns 的解析结果都指到 tun 所在的段,然后这所有流量不就从 tun 走了嘛。。
garryforreg420
5 天前
需要用 "inet4_route_address" 参数自定义路由表,否则默认就是所有流量都进去

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

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

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

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

© 2021 V2EX