安装 OpenVPN 客户端

在 Linux 上设置 VPN 通常有两种角色:作为客户端连接VPN作为服务器搭建VPN服务,以下是常见方法的简要指南:


作为客户端连接VPN

方法1:使用内置网络管理器(GUI)

  • 适用于 OpenVPN、IPsec 等协议:
    1. 下载 VPN 配置文件(通常为 .ovpn 文件)。
    2. 打开 设置 > 网络 > VPN,点击 添加配置。
    3. 选择协议(如 OpenVPN),导入文件并输入凭据。

方法2:命令行(OpenVPN)

sudo dnf install openvpn  # Fedora/CentOS
# 连接 VPN(需配置文件)
sudo openvpn --config client.ovpn

方法3:WireGuard 客户端

# 安装 WireGuard
sudo apt install wireguard  # Debian/Ubuntu
# 使用配置文件连接
sudo wg-quick up /path/to/wg0.conf
# 断开连接
sudo wg-quick down /path/to/wg0.conf

作为服务器搭建VPN

方法1:OpenVPN 服务器

# 安装 OpenVPN 和 Easy-RSA(证书工具)
sudo apt install openvpn easy-rsa
# 初始化 PKI 并生成证书(需交互操作)
make-cadir ~/openvpn-ca
cd ~/openvpn-ca
./easyrsa init-pki
./easyrsa build-ca
./easyrsa gen-req server nopass
./easyrsa sign-req server server
./easyrsa gen-dh
# 复制证书到 OpenVPN 目录
sudo cp ~/openvpn-ca/pki/{ca.crt,dh.pem,issued/server.crt,private/server.key} /etc/openvpn/server/
# 使用示例配置
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/server/
sudo gzip -d /etc/openvpn/server/server.conf.gz
# 启动服务
sudo systemctl start openvpn@server

方法2:WireGuard 服务器

# 安装 WireGuard
sudo apt install wireguard
# 生成密钥对
umask 077
wg genkey | sudo tee /etc/wireguard/private.key
sudo cat /etc/wireguard/private.key | wg pubkey | sudo tee /etc/wireguard/public.key
# 创建配置文件 `/etc/wireguard/wg0.conf`:
[Interface]
PrivateKey = <服务器私钥>
Address = 10.8.0.1/24
ListenPort = 51820
[Peer]
PublicKey = <客户端公钥>
AllowedIPs = 10.8.0.2/32
# 启用服务
sudo wg-quick up wg0
sudo systemctl enable wg-quick@wg0

注意事项

  • 防火墙:确保放行 VPN 端口(如 OpenVPN 的 1194/UDP 或 WireGuard 的 51820/UDP)。
    sudo ufw allow 1194/udp
  • 日志排查:使用 journalctl -u openvpn@serverwg show 查看状态。
  • 安全性:配置防火墙、限制访问、使用强加密算法。

常见 VPN 协议对比

协议 速度 配置难度 加密强度 适用场景
OpenVPN 中等 中等 通用
WireGuard 简单 移动设备/低延迟
IPsec 复杂 企业网络

根据需求选择协议,WireGuard 适合简单高速场景,OpenVPN 兼容性更广。

安装 OpenVPN 客户端

@版权声明

转载原创文章请注明转载自飞鸟VPN加速器- 高速稳定免费VPN加速器 | 飞鸟加速器-全球十大VPN梯子,网站地址:https://wap.feiniao-wap.com.cn/