OpenVPN
安装客户端
sudo apt update sudo apt install openvpn # Debian/Ubuntu sudo yum install openvpn # CentOS/RHEL
配置连接
- 下载VPN配置文件(通常为
.ovpn文件):sudo wget -P /etc/openvpn/ https://your-vpn-provider/config.ovpn
- 启动VPN:
sudo openvpn --config /etc/openvpn/config.ovpn
- 输入用户名/密码(如需)。
自动启动
sudo systemctl enable openvpn@config # 将`config`替换为你的配置文件名(不含.ovpn) sudo systemctl start openvpn@config
WireGuard
安装
sudo apt install wireguard # Debian/Ubuntu sudo yum install wireguard-tools # CentOS/RHEL
配置
-
生成密钥对:
wg genkey | tee privatekey | wg pubkey > publickey
-
创建配置文件
/etc/wireguard/wg0.conf:[Interface] PrivateKey = <你的私钥> Address = VPN分配的IP(如10.0.0.2/24) [Peer] PublicKey = 服务器的公钥 Endpoint = 服务器IP:端口 AllowedIPs = 0.0.0.0/0 # 路由所有流量 PersistentKeepalive = 25
启动
sudo wg-quick up wg0 sudo systemctl enable wg-quick@wg0 # 开机自启
IPSec/L2TP (如Cisco VPN)
使用 strongSwan 或 xl2tpd:
sudo apt install strongswan xl2tpd # Debian/Ubuntu
编辑 /etc/ipsec.conf 和 /etc/xl2tpd/xl2tpd.conf 配置服务器信息,然后启动服务:
sudo systemctl restart strongswan xl2tpd
第三方工具(如PPTP)
注意:PPTP不安全,建议优先使用OpenVPN或WireGuard。
sudo apt install pptp-linux sudo pptpsetup --create <连接名> --server <服务器IP> --username <用户> --password <密码> --encrypt sudo pon <连接名>
验证连接
- 检查IP是否变化:
curl ifconfig.me
- 查看路由表:
ip route
- 检查VPN接口:
ip a show # 或 `ifconfig`
常见问题
- 权限问题:确保使用
sudo或 root 用户操作。 - 防火墙:开放VPN所需端口(如OpenVPN的1194/UDP)。
- 日志排查:
journalctl -u openvpn@config # 查看OpenVPN日志 sudo wg show # 查看WireGuard状态
根据你的VPN协议选择对应方法,确保替换示例中的服务器IP、用户名等参数为实际值,如需更具体的帮助,请提供VPN类型及错误信息。









