我现在有一台有公网 IP 的 Linux 服务器, 由于运行的服务比较敏感不打算对互联网公开, 所以想要部署 WireGuard 确保只有连接 WireGuard 的几台本地电脑才能访问, 同时不影响本地电脑的其他流量. 服务器只开放了 SSH 端口10000, WireGuard 端口20000, 服务器wg0.conf如下:
[Interface]
Address = 10.0.0.1/24
SaveConfig = true
PrivateKey = <服务器私钥>
ListenPort = 20000
[Peer]
PublicKey = <本地电脑公钥>
AllowedIPs = 10.0.0.2/32
本地电脑配置如下:
[Interface]
PrivateKey = <本地电脑私钥>
Address = 10.0.0.2/24
DNS = 223.5.5.5
[Peer]
PublicKey = <服务器公钥>
AllowedIPs = 10.0.0.1/32
Endpoint = my-server-ip:20000
服务器使用systemctl start [email protected] 启动服务之后, 本地电脑成功连接, 在服务器上运行了一个 nginx 监听 80 端口, 浏览器访问10.0.0.1:80成功了.
由于 WireGuard 的官方文档实在有些难懂, 只能根据我的理解和猜测配置完成并且测试了下, 麻烦各位能帮忙指正下这样的配置是否存在问题, 或者还有什么可以优化的地方.