选择VPN协议
常见协议对比:
- OpenVPN:兼容性强,支持TCP/UDP,适合大多数场景。
- WireGuard:性能更高,配置简单,适合移动设备。
- IPSec/L2TP:内置支持(如iOS/Android),但可能被防火墙拦截。
准备服务器
-
选择云服务商(推荐):
- 海外服务器:AWS LightSail、DigitalOcean、Vultr(选择日本、新加坡等亚洲节点延迟较低)。
- 国内访问合规需求:阿里云/腾讯云境外服务器(需备案域名)。
- 最低配置:1核CPU,512MB内存,每月流量≥1TB(约5-10美元/月)。
-
基础设置:
# 更新系统 sudo apt update && sudo apt upgrade -y # 安装必要工具 sudo apt install curl git -y
一键脚本安装(推荐新手)
-
OpenVPN安装:
wget https://git.io/vpn -O openvpn-install.sh && sudo bash openvpn-install.sh
按提示操作,脚本会自动生成客户端配置文件(
.ovpn文件)。 -
WireGuard安装:
curl -O https://raw.githubusercontent.com/angristan/wireguard-install/master/wireguard-install.sh chmod +x wireguard-install.sh sudo ./wireguard-install.sh
脚本会生成二维码和配置文件(
client.conf)。
手动配置(高级用户)
示例:WireGuard服务端配置(/etc/wireguard/wg0.conf):
[Interface] PrivateKey = <服务器私钥> Address = 10.0.0.1/24 ListenPort = 51820 PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE [Peer] PublicKey = <客户端公钥> AllowedIPs = 10.0.0.2/32
客户端连接
- OpenVPN:
- 下载生成的
.ovpn文件,导入到客户端(如OpenVPN Connect)。
- 下载生成的
- WireGuard:
- 手机:扫描脚本生成的二维码。
- PC:复制
client.conf到WireGuard客户端。
安全加固
- 防火墙规则(UFW示例):
sudo ufw allow OpenSSH sudo ufw allow 1194/udp # OpenVPN sudo ufw enable
- 禁用密码登录:
sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config sudo systemctl restart sshd
测速与优化
- 使用
iperf3测试带宽:# 服务端 iperf3 -s # 客户端 iperf3 -c <服务器IP> -p 5201
- 加速建议:
- 启用BBR拥塞控制:
echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.conf echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.conf sudo sysctl -p
- 启用BBR拥塞控制:
常见问题
- Q:连上VPN但无法上网?
A:检查服务器IP转发是否开启(sysctl net.ipv4.ip_forward=1)。 - Q:速度慢?
A:尝试更换协议(如WireGuard),或选择物理距离更近的服务器。
注意事项
- 部分国家/地区对VPN有法律限制,请确保合规使用。
- 避免在服务器上运行其他服务以减少暴露风险。
如果需要更详细的配置(如多用户管理、流量监控),可考虑使用管理面板如wg-easy(WireGuard)或OpenVPN-Admin。









