Wireguard 通过服务器从客户端转发到客户端网络

Wireguard foward from client via server to client's network

所以我有一台本地电脑,我想通过 wireguard 连接到远程网络。我无法在远程网络中打开端口,所以我在两者之间添加了一个服务器。

我可以通过 vpn 从笔记本电脑和远程网络的入口点 ping 服务器。 我可以从服务器 ping 笔记本电脑和入口点

我无法从笔记本电脑 ping 入口点。
我无法从笔记本电脑 ping 远程网络。

配置:
服务器

 [Interface]
Address = 10.5.0.1/24
ListenPort = 1194
PrivateKey = <PrivateKey>    

[Peer]
PublicKey = <PublicKey>
AllowedIPs = 10.5.0.2/32,192.168.1.200/16

[Peer] # Laptop
PublicKey = <PublicKey>
AllowedIPs = 10.5.0.200/32

笔记本电脑:

[Interface]
PrivateKey = <PrivateKey>
Address = 10.5.0.200/32

[Peer]
PublicKey = <PublicKey>
Endpoint = <ServerIP>:1194
AllowedIPs = 10.5.0.0/16,192.168.0.0/16
PersistentKeepalive = 15

远程网络的入口点:

[Interface]
PrivateKey = <PrivateKey>
Address = 10.5.0.2/32

[Peer]
PublicKey = <PublicKey>
Endpoint = <ServerIP>:1194
AllowedIPs = 10.5.0.0/16
PersistentKeepalive = 15

我还在服务器和入口点上设置了 sysctl -w net.ipv4.ip_forward=1

解决方案是添加

PostUp   = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT;
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT;

到服务器的[接口]

并添加

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

到入口点的[接口]