分享自用 WireGuard S2S 配置

· 97 words · 1 minute read

警告

这不是任何产品的官方文档、帮助或使用说明,仅代表博主个人的经验总结,难免会有疏漏和错误之处。请务必结合官方文档进行阅读,以作补充。

警告

博主对网络和 WireGuard 了解甚少,所以本篇文章仅作为配置分享和水文之用,恕不进行深入讲解。

环境:

  • 本地:10.0.100.0/24(家里网络)
  • 远程:172.16.0.0/24(Azure 服务器)
  • WireGuard 地址:192.168.0.1/24 和 192.168.0.2/24
  • 远程外部地址::
# 远程配置
[Interface]
Address = 192.168.1.1
ListenPort = <监听端口>
PrivateKey = <远端私钥>
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
 
[Peer]
PublicKey = <本地公钥>
AllowedIPs = 10.0.100.0/24, 192.168.1.0/24
PersistentKeepalive = 15
# 本地配置
[Interface]
ListenPort = <本地监听地址,随便填写即可>
PrivateKey = <本地私钥>
 
[Peer]
PublicKey = <远程公钥>
AllowedIPs = 172.16.0.0/12, 192.168.1.0/24
Endpoint = <远程地址>:<远程端口>
PersistentKeepalive = 15