请教一下这种情况下 iptables 该怎样写

2019-08-29 08:18:22 +08:00
 chunchu

网络简图见下图:

     A                B(Raspberry Pi)              C(VPS)         
192.168.0.*   <--->   192.168.0.112          111.111.111.111   <--->   Internet
                        10.0.2.60     <--->     10.0.2.251
                           tinc                    tinc

A(PC):

B(Raspberry Pi):

C(VPS):

A(PC)与 B(Raspberry Pi)同属 192.168.0.0/24,B(Raspberry Pi)与 C(VPS)通过 tinc 连接,现在想要实现的效果是:A(PC)将网关设置 192.168.0.112 ,所有流量经过 B(Raspberry Pi),然后流量通过 tinc 到达 C(VPS)出口。这样考虑的原因主要是因为 tinc 比较稳定,使用的人也比较少。网络上有使用 OpenVPN 这样干的,但是 OpenVPN 与 tinc 还是稍有差异。V2EX 上这样干过的讨论一下,谢谢!

2566 次点击
所在节点    问与答
24 条回复
chunchu
2019-08-30 09:20:24 +08:00
@xduanx
我先自己弄一下,万一还是搞不定再来请教你,谢谢了!
chunchu
2019-09-02 17:42:59 +08:00
Padawan
2020-03-15 21:49:02 +08:00
@xduanx
hello, 我遇到了类似但略有不同的问题, 能不能请你帮看一下应该怎么解决?

LAN:
192.168.1.0/24

树莓派:
eth0: 192.168.1.2
Wireguard 虚拟网卡: 192.168.3.1

LAN 网关:
192.168.1.1

网络是
LAN 网关->光猫->WAN

现在树莓派上做的透明代理设置可以正常工作. 但是作为 Wireguard 服务器, 外面连进来的客户端无法访问 LAN 也无法访问互联网. 是需要增加路由设置吗?

我如果把 ip route add local 0.0.0.0/0 dev lo table 100 去掉, Wireguard 客户端连进来后可以访问 192.168.3.1,但是无法访问 WAN.

我需要做什么改动才能保持透明代理的同时让 Wireguard 客户端接入后也能访问 LAN 和 WAN 呢?

透明代理是通过写在 /etc/rc.local 里的
ip rule add fwmark 1 table 100
ip route add local 0.0.0.0/0 dev lo table 100
...


以下是我设上透明代理和 Wireguard 后的配置.

# ip route list table main
default via 192.168.1.1 dev eth0 src 192.168.1.2 metric 202
192.168.1.0/24 dev eth0 proto dhcp scope link src 192.168.1.2 metric 202
192.168.3.0/24 dev wg0 proto kernel scope link src 192.168.3.1

# ip route list table 100
local default dev lo scope host

# ip rule list
0: from all lookup local
32765: from all fwmark 0x1 lookup 100
32766: from all lookup main
32767: from all lookup default
yanshibin
2021-06-21 22:15:15 +08:00
@xduanx 您好,我有遇到类似的问题,能否付费请教下,留个联系方式

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

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

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

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

© 2021 V2EX