关于 wireguard server 和 client 在同一台服务器上, 无法连接问题。

2021-09-16 13:02:14 +08:00
 guanyin9cn

RT,

根据这个 reddit 讨论做的 ,www.reddit.com/r/WireGuard/comments/ekeprt/wireguard_to_wireguard_setup_im_sure_many_have

centos 7 中继。

数据流是 :wg client (openwrt ) --> wg server (centos7) --> wg client(centos7) ---> vps

server, wg0.conf 的配置

[Interface]
PrivateKey = 
Address = 10.0.1.1/24
PostUp   = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o ens192 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o ens192 -j MASQUERADE
ListenPort = 443
MTU = 1420
FwMark = 51820

[PEER]
PUBLICKEY = 
ALLOWEDIPS = 

client , vpn-client.conf

[Interface]
PrivateKey =
Address = 10.0.2.11/32
MTU = 1420
FwMark = 51820

PostUp   = iptables -t nat -A POSTROUTING -o vpn-client -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -o vpn-client -j MASQUERADE

[Peer]
PublicKey =
Endpoint =
PersistentKeepalive = 25
AllowedIPs = 0.0.0.0/0

server 和 client 的 FwMark 均设置为 51820 。

现状是 通过 openwrt 连接 server 时,可以通过 10.0.1.1 访问 centos7.

在 centos7 可以访问 ping 公网网关。 但是 在 本地 pc 上,或者其他 服务器上,无法 ping centos7 的 公网 ip,不通。

能从 wg client 的情况下 访问的原因,看了下 iptables 的 mangle 表 , 应该只允许了 udp 。

-A PREROUTING -p udp -m comment --comment "wg-quick(8) rule for vpn-client" -j CONNMARK --restore-mark --nfmask 0xffffffff --ctmask 0xffffffff
-A POSTROUTING -p udp -m mark --mark 0xca6c -m comment --comment "wg-quick(8) rule for vpn-client" -j CONNMARK --save-mark --nfmask 0xffffffff --ctmask 0xffffffff

@dndx

1219 次点击
所在节点    Linux
0 条回复

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

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

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

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

© 2021 V2EX