购买 VPS
推荐选择:
- DigitalOcean (www.digitalocean.com)
- Linode (www.linode.com)
- Vultr (www.vultr.com)
- AWS Lightsail (aws.amazon.com/lightsail)
选择离你较近的区域(如日本、新加坡、美国等)。
连接到 VPS
使用 SSH 登录:
ssh root@your_vps_ip
安装 WireGuard
Ubuntu/Debian
sudo apt update && sudo apt upgrade -y sudo apt install wireguard -y
CentOS/RHEL
sudo yum install epel-release -y sudo yum install wireguard-tools -y
生成密钥对
cd /etc/wireguard umask 077 wg genkey | tee privatekey | wg pubkey > publickey
配置 WireGuard 服务器
创建配置文件 /etc/wireguard/wg0.conf:
[Interface] PrivateKey = <SERVER_PRIVATE_KEY> # 从 privatekey 文件获取 Address = 10.0.0.1/24 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] PublicKey = <CLIENT_PUBLIC_KEY> # 客户端生成的公钥 AllowedIPs = 10.0.0.2/32
- 替换
<SERVER_PRIVATE_KEY>和<CLIENT_PUBLIC_KEY>。 - 确保启用 IP 转发:
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf sysctl -p
启动 WireGuard
wg-quick up wg0 systemctl enable wg-quick@wg0
配置客户端
在本地设备(Windows/macOS/Linux/Android/iOS)安装 WireGuard,生成密钥对,并创建配置文件:
[Interface] PrivateKey = <CLIENT_PRIVATE_KEY> Address = 10.0.0.2/24 DNS = 8.8.8.8 [Peer] PublicKey = <SERVER_PUBLIC_KEY> # 服务器的公钥 Endpoint = <VPS_IP>:51820 AllowedIPs = 0.0.0.0/0 PersistentKeepalive = 25
导入配置文件到 WireGuard 客户端并连接。
其他 VPN 方案
- OpenVPN:更复杂但功能丰富(适合企业)。
- IPsec/L2TP:兼容性强(适合移动设备)。
- Shadowsocks:适合绕过审查(非传统 VPN)。
如果需要详细教程,可以告诉我你的具体需求(如协议、用途等),我会提供更精准的指南!








