
在 VPS 上自托管 WireGuard VPN。
十五分钟拥有你自己的个人 VPN。
从"没有服务器"到"我自己的个人 VPN"的五个步骤——注册无需 KYC,加密货币付款,信任链中无第三方 VPN 提供商。在 Debian 12 上使用主线内核中的 WireGuard 1.0+ 测试。
- 01
配置
Nordic VPS
- 02
安装
apt install wireguard
- 03
配置
密钥 + wg0.conf
- 04
防火墙
UDP 51820 + 转发
- 05
连接
wg-quick up wg0
选择一个靠近你所在位置的 Nordic 堡垒。
在面板中:Order → VPS → Sentinel($5.90/月,2 vCPU / 4 GB / 120 GB NVMe)。Sentinel 拥有无限带宽和 1 Gbps 上行——即使满速流媒体也足以用于个人 VPN。选择离你实际位置最近的堡垒,因为你发送的每个字节都要经过 VPS 再到达目的地。欧洲客户选择 Stockholm 或 Helsinki;美洲/亚洲客户选择 Reykjavík(最低跨大西洋延迟)或 Oslo。
OS 镜像:推荐 Debian 12。Ubuntu 22.04+ 运行方式相同。Alpine 可用但使用不同的包名(apk add wireguard-tools)。FreeBSD 也可用,但配置语法有所差异。服务器约 90 秒内启动;root 凭证在面板中展示一次。
一个软件包,已在内核中。
以 root 身份通过 SSH 登录。然后:
apt update
apt install -y wireguard qrencode
就这样。WireGuard 自 5.6 版本(2020 年 3 月)起已并入 Linux 主线内核,因此 apt 只需安装用户空间工具(wg、wg-quick)——无需编译模块、无需 DKMS、无需重建内核。qrencode 软件包将在第 5 步中用于将客户端配置以二维码形式推送到手机。
现在启用 IP 转发,以免在第 4 步遗忘:
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.conf
sysctl -p
生成密钥,写入 wg0.conf。两分钟。
生成服务器密钥对:
cd /etc/wireguard
umask 077
wg genkey | tee server_private.key | wg pubkey > server_public.key
现在为每台设备生成一个客户端密钥对:
wg genkey | tee laptop_private.key | wg pubkey > laptop_public.key
wg genkey | tee phone_private.key | wg pubkey > phone_public.key
创建 /etc/wireguard/wg0.conf,包含服务器设置和每个客户端一个 [Peer] 块:
[Interface]
PrivateKey = <contents of server_private.key>
Address = 10.66.66.1/24, fd00:66::1/64
ListenPort = 51820
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
[Peer]
# laptop
PublicKey = <contents of laptop_public.key>
AllowedIPs = 10.66.66.2/32
[Peer]
# phone
PublicKey = <contents of phone_public.key>
AllowedIPs = 10.66.66.3/32
开放 UDP 51820。锁定其余端口。
若使用 UFW(Ubuntu 默认):
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp # SSH (consider port-knocking or VPN-only in production)
ufw allow 51820/udp # WireGuard
ufw enable
NordBastion 堡垒还有一个从面板管理的上游防火墙——你可以在那里复制相同规则以实现纵深防御。堡垒级防火墙在数据包到达 VPS 之前就进行拦截,节省了流量扫描的 CPU 资源。
值得遵循的隐私建议:将 WireGuard 的 ListenPort 从 51820(默认值,扫描器会寻找)改为 1024 至 65535 之间的随机端口。这对有针对性的攻击者没有安全提升,但能减少随机扫描器的干扰。
建立隧道。第一个客户端秒级接入。
在服务器上:
systemctl enable --now wg-quick@wg0
wg # status: should show interface up
在服务器上构建客户端配置(laptop.conf),然后将其复制到笔记本电脑:
[Interface]
PrivateKey = <contents of laptop_private.key>
Address = 10.66.66.2/24, fd00:66::2/64
DNS = 1.1.1.1, 9.9.9.9 # or your favourite privacy resolver
[Peer]
PublicKey = <contents of server_public.key>
Endpoint = <server-ip>:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
对于移动设备,通过 qrencode 将配置转为二维码并用 WireGuard 应用扫描:
qrencode -t ansiutf8 < phone.conf
就这样。客户端连接,隧道建立,笔记本电脑/手机现在通过 Nordic 堡垒节点访问互联网。验证方法:curl https://api.ipify.org——返回的 IP 是 VPS 的公网 IP,而非您家的 IP。
问题,已解答。
首次自托管 VPN 客户提出的八个问题。
为何自托管 WireGuard VPN 而非使用 NordVPN / Mullvad / ProtonVPN?
三个真实原因。(1)信任链缩短。商业 VPN 是」相信这家公司不会记录您「;自托管则是」相信这家 VPS 服务商不会记录您」——少了一个中间方。(2)VPN 出口 IP 专属于您。商业 VPN 出口 IP 由数千用户共享,且被众多服务封锁;您的自托管出口是一个从未被标记的全新干净 IP。(3)成本。NordBastion Sentinel 每月 $5.90,可运行无限带宽 VPN;商业 VPN 为共享基础设施,每月 $5-$15。
为何选择 WireGuard 而非 OpenVPN?
WireGuard 更小(4,000 行内核代码对比 OpenVPN 的约 100,000 行),更快(在相同硬件上吞吐量通常高出 3-5 倍),配置更简单(单一配置文件,无需 CA/证书/dhparam 配置),且易于审计。自 5.6 版本(2020 年)起已并入 Linux 主线内核,无需编译步骤。OpenVPN 在旧版兼容性和基于 TCP 的流量场景下仍有价值;其他一切场景 WireGuard 是现代默认选择。
我的 ISP 知道我在运行 VPN 吗?
您的 ISP 看到的是发往 NordBastion IP 的 51820 端口加密 UDP 流量。该模式可被识别为 VPN 流量;但另一侧的内容无法识别。如果在您的场景中「运行 VPN 本身」是敏感的,请在 443 端口运行 WireGuard(它使用 UDP 而非 TCP,但端口与 HTTPS 相同),并考虑使用 udp2raw 等混淆封装器,以防 ISP 主动封锁 WireGuard 握手。
我可以将 VPS 同时用作 VPN 和其他用途的服务器吗?
是的,这是常见模式。VPS 运行 WireGuard 加上您所需的其他任何内容——个人网站、Bitcoin 节点、Mastodon 实例。防火墙规则将 VPN 流量与面向公众的服务隔离;iptables/nft 可将 VPN 客户端路由到特定本地服务而非其他服务。
关于 IP 地理位置——网站会认为我在瑞典吗?
是——您的出口 IP 是您选择的 NordBastion 堡垒节点。按 IP 地理围栏的流媒体服务会将您视为瑞典人(Stockholm 堡垒)、芬兰人(Helsinki)、挪威人(Oslo)或冰岛人(Reykjavík)。标记「从新国家登录」的银行网站会触发其欺诈规则;这是正常行为,而非 VPN 问题。
一台 WireGuard 服务器可以处理多少个客户端?
个人使用实际上无上限。每个对等节点增加几 KB 内存。制约因素是带宽和堡垒的上行链路,而非 WireGuard 守护进程本身。拥有无限带宽和 1 Gbps 上行链路的 Sentinel 档位会在 WireGuard 进程察觉之前先达到饱和。
我应该在独立 VPS 上运行,还是与其他工作负载共享?
从 OPSEC 角度看,专用 VPS 更清晰——该 IP 唯一关联的是"我的个人 VPN"。若混合工作负载,VPN 流量与其他工作负载的流量共享出站 IP,任意一方的信誉问题都会波及另一方。以 $5.90/月的价格,将其分开是合理的。
自托管 WireGuard 是否具备断网保护功能?
是的,客户端侧。WireGuard 配置支持 PostUp / PostDown 块,您在其中添加 iptables 规则,在隧道启动时丢弃非 VPN 流量;您也可以将客户端操作系统设置为默认拒绝非 VPN 连接。数个开源管理应用(wg-easy、WireGuard-UI、Pi-VPN)为您封装了这一功能。
订购 Sentinel 并启动你自己的 VPN。
最后审核 · 2026-05-20 · 已测试 · Debian 12 · WireGuard 1.0.20210914
Anonymous VPS hosting in 2026 — the cluster.
This guide is one spoke of a larger series. The pillar walks the three privacy layers end to end — the sibling spokes below dive into the specifics.
Three independent layers — signup, payment, network — explained, legal context included, common mistakes flagged.
A v3 .onion address that survives reboots and IP changes.
What “no KYC” actually means — and what it does not.
Why Sweden, Finland, Norway and Iceland — the legal floor of each.
XMR end-to-end — wallet, transfer, confirmations, change.