安装WireGuard
根据你的操作系统安装WireGuard工具:
- Debian/Ubuntu
sudo apt update sudo apt install wireguard
- Fedora
sudo dnf install wireguard
- Arch Linux
sudo pacman -S wireguard
生成并设置WireGuard键
进入WireGuard配置目录:
cd /etc/wireguard
生成并设置接口的密钥:
wg genkey wg showkey -A > wg.key
下载配置文件
使用curl下载配置文件,假设你的配置文件位于https://example.com/wg.conf:
curl -o wg.conf https://example.com/wg.conf
配置 WireGuard 接口
编辑配置文件wg.conf,添加以下内容:
[Interface] PrivateKey = your_private_key_here ListenPort = 518 [Peer] AllowedIPs = 0.../24 Endpoint = your_server_ip:518
启动 WireGuard
使用wg-quick命令启动接口,并指定私钥文件:
wg-quick up wg -i wg.key
连接测试
检查连接状态:
wg show-state wg
后续操作
-
重启服务:如果需要重启 WireGuard 服务,可以运行:
sudo systemctl restart wg-quick@wg
-
检查日志:查看日志以解决问题:
journalctl -u wg-quick@wg -b
-
防火墙设置:确保防火墙开放了相关端口,
sudo ufw allow out 518
注意事项
- 生成密钥:确保
wg genkey生成的密钥正确无误。 - 服务器配置:确认服务器配置正确,包括NAT和端口转发。
- 日志检查:遇到问题时,检查日志以获取详细信息。
通过以上步骤,你可以成功配置并使用 WireGuard VPN。




