使用商业 VPN 服务(推荐新手)
-
选择 VPN 提供商
- 常见选项:NordVPN、ExpressVPN、Surfshark、ProtonVPN 等。
- 确保提供商支持 Linux(多数提供 OpenVPN 或 WireGuard 配置文件)。
-
安装 VPN 客户端
-
方法1:图形界面(推荐)
- 从官网下载
.deb安装包(如 NordVPN 的nordvpn-release_1.0.0_all.deb)。 - 安装:
sudo apt install ./nordvpn-release_1.0.0_all.deb sudo apt update sudo apt install nordvpn
- 登录并连接:
nordvpn login nordvpn connect
- 从官网下载
-
方法2:手动配置 OpenVPN
- 安装 OpenVPN:
sudo apt install openvpn
- 下载提供商提供的
.ovpn配置文件(通常从官网获取)。 - 连接:
sudo openvpn --config /path/to/config.ovpn
- 安装 OpenVPN:
-
-
验证连接
- 检查 IP 是否变化:
curl ifconfig.me
- 测试网络:
ping google.com
- 检查 IP 是否变化:
自建 VPN 服务器(高级用户)
选项1:WireGuard(高性能,推荐)
-
服务器端(如 VPS)
-
安装 WireGuard:
sudo apt install wireguard
-
生成密钥:
wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey
-
创建配置文件
/etc/wireguard/wg0.conf:[Interface] 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 = <客户端公钥> AllowedIPs = 10.0.0.2/32
-
-
客户端(Ubuntu)
-
安装 WireGuard:
sudo apt install wireguard
-
创建配置文件
/etc/wireguard/wg0.conf:[Interface] PrivateKey = <客户端私钥> Address = 10.0.0.2/24 [Peer] PublicKey = <服务器公钥> Endpoint = <服务器IP>:51820 AllowedIPs = 0.0.0.0/0 # 路由所有流量
-
-
启动服务
- 服务器和客户端均执行:
sudo wg-quick up wg0
- 设置开机自启:
sudo systemctl enable wg-quick@wg0
- 服务器和客户端均执行:
选项2:OpenVPN
-
服务器端
- 使用脚本快速安装:
wget https://git.io/vpn -O openvpn-install.sh && sudo bash openvpn-install.sh
- 按提示操作,生成客户端配置文件(
.ovpn)。
- 使用脚本快速安装:
-
客户端
- 安装 OpenVPN:
sudo apt install openvpn
- 导入
.ovpn文件并连接:sudo openvpn --config client.ovpn
- 安装 OpenVPN:
常见问题
-
连接失败
- 检查防火墙(UFW/iptables)是否放行 VPN 端口(如 51820/WireGuard)。
- 确保服务器 IP 和路由配置正确。
-
DNS 泄露
- 使用 VPN 提供的 DNS,或手动设置:
sudo resolvectl dns wg0 1.1.1.1
- 使用 VPN 提供的 DNS,或手动设置:
-
速度慢
尝试更换服务器节点或协议(如从 OpenVPN 切换到 WireGuard)。
- 新手:优先选择商业 VPN 服务,使用官方客户端或 OpenVPN。
- 技术用户:自建 WireGuard 服务器,获得更高可控性和性能。
根据需求选择合适方案,并注意网络安全和隐私保护。
