华硕梅林固件 WireGuard 作为服务器可以向上级路由转发,作为客户端不可以?

37 天前
 MuJian
两台梅林:
一台 ip 192.168.0.1 ,作为 wireguard 服务器, 192.168.6.2 连接他;
一台 ip 192.168.2.1 ,作为客户端,连接服务器 192.168.6.2 ;

192.168.6.0/24 设备可以访问 192.168.0.1/24 ,以及 192.168.0.1 的上级任意路由,比如 192.168.10.0/24 ;
192.168.6.0/24 设备可以访问 192.168.2.0/24 ,但是不能访问 192.168.2.1 的上级路由器,比如 192.168.12.0/24

通过查询 iptable 规则,FOREWARD 表一摸一样

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 1585K 734M IPSEC_DROP_SUBNET_ICMP all -- * * 0.0.0.0/0 0.0.0.0/0
2 1585K 734M IPSEC_STRONGSWAN all -- * * 0.0.0.0/0 0.0.0.0/0
3 31466 1841K TCPMSS tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcpflags: 0x06/0x02 TCPMSS clamp to PMTU
4 1562K 732M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
5 22979 1679K WGSF all -- * * 0.0.0.0/0 0.0.0.0/0
6 16498 1297K OVPNSF all -- * * 0.0.0.0/0 0.0.0.0/0
7 0 0 DROP all -- !br0 ppp0 0.0.0.0/0 0.0.0.0/0
8 0 0 DROP all -- !br0 eth4 0.0.0.0/0 0.0.0.0/0
9 4 224 ACCEPT all -- br0 br0 0.0.0.0/0 0.0.0.0/0
10 988 42138 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 state INVALID
11 564 31554 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate DNAT
12 14942 1223K WGCF all -- * * 0.0.0.0/0 0.0.0.0/0
13 14942 1223K OVPNCF all -- * * 0.0.0.0/0 0.0.0.0/0
14 14942 1223K VPNCF all -- * * 0.0.0.0/0 0.0.0.0/0
15 14942 1223K ACCEPT all -- br0 * 0.0.0.0/0 0.0.0.0/0
16 0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0


仅有作为服务器的 192.168.0.1 ,wireguard 的规则被放到了 WGSF ,WGSI 里
Chain WGSF (1 references)
num pkts bytes target prot opt in out source destination
1 6413 378K ACCEPT all -- * wgs1 0.0.0.0/0 0.0.0.0/0
2 68 4080 ACCEPT all -- wgs1 * 0.0.0.0/0 0.0.0.0/0

Chain WGSI (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:59999
2 570 29640 ACCEPT all -- wgs1 * 0.0.0.0/0 0.0.0.0/0


作为客户端的 192.168.2.1 ,wireguard 规则被放到了 WGCF ,WGCI 里

Chain WGCF (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 TCPMSS tcp -- * wgc1 0.0.0.0/0 0.0.0.0/0 tcpflags: 0x06/0x02 TCPMSS clamp to PMTU
2 0 0 ACCEPT all -- * wgc1 0.0.0.0/0 0.0.0.0/0
3 6082 365K ACCEPT all -- wgc1 * 0.0.0.0/0 0.0.0.0/0
4 0 0 TCPMSS tcp -- * wgc2 0.0.0.0/0 0.0.0.0/0 tcpflags: 0x06/0x02 TCPMSS clamp to PMTU
5 0 0 ACCEPT all -- * wgc2 0.0.0.0/0 0.0.0.0/0
6 458 27480 ACCEPT all -- wgc2 * 0.0.0.0/0 0.0.0.0/0

Chain WGCI (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 ACCEPT all -- wgc1 * 0.0.0.0/0 0.0.0.0/0
2 855 44460 ACCEPT all -- wgc2 * 0.0.0.0/0 0.0.0.0/0


个人粗浅的理解,应该没有限制才对?



那么唯一的区别就是做位客户端也收到 VPN Director 限制
但是 VPN Director 规则好像只能指定出口

我已经指定远程 ip 192.168.6.0/24 走 WGC2 ,但是只能是让 192.168.2.0/24 和 192.168.6.0/24 互访。


请教我应该如何设置能让 192.168.6.0/24 设备能够访问 192.168.12.0/24 ?
955 次点击
所在节点    宽带症候群
8 条回复
ranaanna
37 天前
192.168.6.0/24 设备之所以能访问 192.168.10.0/24 ,是因为 192.168.0.1 对来自 192.168.6.0/24 的流量进行了 SNAT 或 masquerading 。所以要能访问 192.168.12.0/24 ,需要 192.168.2.1 也做同样的事情。这是 iptables nat 表的事情。
ranaanna
37 天前
没用过华硕的固件,但是感觉这个 vpn director 就是干这件事的,即让一端的 lan 通过隧道到另一端出去。这是单向的。所以要实现双向,需要增加一条隧道。
ranaanna
37 天前
抱歉应该和 vpn director 没有关系。似乎 iptables rules 可以解决?
···
iptables -t nat -A POSTROUTING -s 192.168.6.0/24 -d 192.168.10.0/24 -j SNAT --to-source 192.168.0.1
iptables -t nat -A POSTROUTING -s 192.168.6.0/24 -d 192.168.12.0/24 -j SNAT --to-source 192.168.2.1
···
MuJian
37 天前
@ranaanna
我开始也以为是 nat 的事,但是我查了 dat 表也是一样的。

Chain POSTROUTING (policy ACCEPT 4770 packets, 314K bytes)
pkts bytes target prot opt in out source destination
201K 14M PUPNP all -- * ppp0 0.0.0.0/0 0.0.0.0/0
107K 7637K MASQUERADE all -- * ppp0 !120.4.83.xxx 0.0.0.0/0
71 3355 MASQUERADE all -- * eth4 !192.168.10.2 0.0.0.0/0
381 78173 MASQUERADE all -- * br0 192.168.0.0/24 192.168.0.0/24
MuJian
37 天前
增加了 snat 也是不通

Chain POSTROUTING (policy ACCEPT 111 packets, 7052 bytes)
pkts bytes target prot opt in out source destination
2268 182K PUPNP all -- * ppp0 0.0.0.0/0 0.0.0.0/0
862 87511 MASQUERADE all -- * ppp0 !120.4.83.169 0.0.0.0/0
20 1200 MASQUERADE all -- * eth4 !192.168.12.4 0.0.0.0/0
979 79728 MASQUERADE all -- * br0 192.168.2.0/24 192.168.2.0/24
0 0 SNAT all -- * * 192.168.6.0/24 192.168.12.0/24 to:192.168.2.1
ranaanna
37 天前
先不管其他设备( VPN director ),隧道的地址只有两个:192.168.6.1 (假设服务器的地址)和 192.168.6.2 。192.168.6.2 这边应该没有问题,12 本来就可以访问,10 通过 nat 访问。但是 192.168.6.1 ,按照规则转换为 eth4 10 的地址,当然就访问不了 12 的地址了。还是 nat 的问题,并不是两边一样就可以访问的。
最简单粗暴的解决办法是再增加一条隧道。
ranaanna
37 天前
或者说大多数情况下 VPN 都是选择一个 remote gateway 出去。像这样 multiple gateways 的情况,估计需要额外的 nat 设计才能达到目的
MuJian
37 天前
@ranaanna 如果梅林作为服务器端,让 192.168.6.2 取连他就能访问上级路由。

我刚又发现,192.168.0.1 里面有路由
192.168.6.0/24 dev wgs1 scope link
192.168.9.6 dev wgs1 scope link
但是手动给 192.168.2.1 添加
ip route add 192.168.6.0/24 dev wgc2 scope link
ip route add 192.168.8.2 dev wgc2 scope link

最后还是不通,看来应该还是 vpn director 接管了路由。

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

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

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

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

© 2021 V2EX