教程

搭建 WireGuard VPN 服务器

WireGuard 是最快最简的现代 VPN 协议。Hostiger 提供预配置 WireGuard VPS 起价 $15/月。本指南同时讲解预配置和在任意 Linux VPS 上手动搭建两种方法。

预计时间: 10 min 费用: $15/mo 更新于: 2026-07-15
1

部署 WireGuard VPS

最快方式:订购 Hostiger WireGuard VPS 起价 $15/月。WireGuard 已装、IP-forward 已启。若使用此路径可跳到第 5 步。

2

手动:安装 WireGuard

在任意 Ubuntu 22.04/24.04 VPS 运行 apt update && apt install wireguard-tools -y。用 wg --version 验证。

3

手动:生成密钥

wg genkey | tee privatekey | wg pubkey > publickey。这会创建服务器密钥对。两份内容都要妥善保存。

4

创建 /etc/wireguard/wg0.conf

含内部子网(10.8.0.0/24)、服务器私钥和监听端口(51820)的配置。为公共接口设置 PostUp/PostDown 规则实现 NAT 伪装。

5

启用 IP-forward + 启动隧道

/etc/sysctl.conf 设置 net.ipv4.ip_forward=1,然后 sysctl -p。启动:systemctl enable --now wg-quick@wg0

6

添加客户端 peer

为客户端生成密钥对。在 wg0.conf 添加 [Peer] 块,含客户端公钥和 AllowedIPs(例 10.8.0.2/32)。重启隧道。

7

创建客户端配置

文件含客户端私钥、服务器公钥、endpoint(server-ip:51820)和 DNS(1.1.1.1)。导入 iOS/Android/macOS/Windows/Linux 上的 WireGuard 应用。

8

测试隧道

在客户端激活隧道。访问 ipleak.net — 公共 IP 应显示为 Hostiger VPS 的 IP。服务器上 wg show 确认握手。

准备好尝试了吗?

60 秒内部署 Hostiger VPS。

获取 WireGuard VPS