现在搭好了一个 Wireguard 的服务端,这里姑且称为 ServerA 。ServerA 上生成了一对 PublicKey 和 PrivateKey ,这里称为 PubKeyA 和 PrivKeyA 。
-
ServerA 的 wg0.conf 配置文件如下:
[Interface] Address = 10.0.0.1/24 SaveConfig = true ListenPort = 51820 PrivateKey = PrivKeyA 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 -
随后通过 systemd 启动 Wireguard ,并通过命令看到 Wireguard 正在运行:
interface: wg0 public key: PubKeyA private key: (hidden) listening port: 51820 -
构建客户端配置文件
这个时候 Windows 端的 Wireguard 会自动生成一组公钥私钥,那么在客户端的配置文件中应该用哪个公钥和哪个私钥呢[Interface] PrivateKey = Address = 10.0.0.1/24 [Peer] PublicKey = AllowedIPs = 0.0.0.0/0 Endpoint = myserver.cn:51820