下载 WireGuard 源代码
WireGuard 的最新版本可以从其官方 GitHub 仓库下载:
https://github.com/wireguard/wireguard
安装依赖软件包
根据你的操作系统,安装必要的依赖项:
- Debian/Ubuntu:
sudo apt-get install -y git make curl software-properties-common
- Fedora:
sudo dnf install -y git make curl
- RHEL/CentOS:
sudo yum install -y git make curl
编译 WireGuard
克隆仓库并编译:
git clone https://github.com/wireguard/wireguard.git cd wireguard make
安装 WireGuard
编译好的软件包位于 ./wireguard 目录:
sudo make install
配置 WireGuard
使用以下命令创建一个新的 WireGuard 接口:
wg create
这将生成一个新的接口文件,wg。
设置 IP 均匀子网(可选)
如果你需要为多个用户或设备分配私有 IP 地址,可以执行以下命令:
wg create-subnet-ipv4 32
设置 DNS 服务器
为 WireGuard 接口配置 DNS 服务器:
wg set wg nameserver 8.8.8.8
启动 WireGuard 服务
如果你需要 WireGuard 作为服务器,启动服务并设置监听端口:
wg serve wg
连接到 WireGuard 服务器
如果你连接到一个远程 WireGuard 服务器,可以使用以下命令:
wg-quick connect <server-public-key>
生成 API 密钥
如果你需要通过 API 访问 WireGuard 服务,可以生成 API 密钥:
wg api generate
测试连接
确认 WireGuard 接口是否正常工作:
wg show wg
卸载 WireGuard
如果不再需要 WireGuard,可以卸载:
sudo make uninstall
注意事项
- 权限:确保你有足够的权限运行 WireGuard,可能需要使用
sudo。 - 系统版本:确保你的系统支持 WireGuard 的最新版本。
- 依赖项:如果在编译过程中遇到问题,确保所有依赖项已正确安装。
如果你遇到任何问题,可以参考 WireGuard 的官方文档或社区获取帮助。









