WireGuard

WireGuard

hgf9511443 2026-07-04 快连加速器官方下载 2 次浏览 0个评论

在 Linux VPS 上搭建 VPN(如 OpenVPNWireGuard)可以为你提供安全的远程访问和网络加密,以下是两种主流方案的快速指南:


方案1:WireGuard(推荐)

WireGuard 是现代、高效且配置简单的 VPN 协议。

步骤

  1. 连接 VPS

    ssh root@your_vps_ip
  2. 安装 WireGuard

    sudo apt update && sudo apt install wireguard -y  # Debian/Ubuntu
    sudo yum install epel-release && sudo yum install wireguard-tools -y  # CentOS
  3. 生成密钥对

    umask 077
    wg genkey | tee privatekey | wg pubkey > publickey
  4. 配置服务端 创建 /etc/wireguard/wg0.conf

    [Interface]
    Address = 10.0.0.1/24
    PrivateKey = <粘贴服务端的privatekey>
    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 = <客户端的publickey>
    AllowedIPs = 10.0.0.2/32
  5. 启用 IP 转发

    echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
    sysctl -p
  6. 启动 WireGuard

    wg-quick up wg0
    systemctl enable wg-quick@wg0
  7. 客户端配置 创建客户端配置文件(如 client.conf):

    [Interface]
    PrivateKey = <客户端的privatekey>
    Address = 10.0.0.2/24
    [Peer]
    PublicKey = <服务端的publickey>
    Endpoint = your_vps_ip:51820
    AllowedIPs = 0.0.0.0/0
    PersistentKeepalive = 25

方案2:OpenVPN

OpenVPN 功能丰富,但配置稍复杂。

快速安装(使用脚本)

  1. 运行自动化脚本

    wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh
    • 按提示输入配置(如 IP、端口、协议等)。
    • 脚本会自动生成客户端配置文件(.ovpn 文件)。
  2. 下载客户端配置

    scp root@your_vps_ip:~/client.ovpn ~/
  3. 客户端使用


防火墙设置

确保放行 VPN 端口:

# OpenVPN
ufw allow 1194/udp  # 默认端口

注意事项

  1. 安全建议

    • 使用非默认端口。
    • 限制 VPN 端口的访问 IP(如仅允许本国 IP)。
    • 定期更新软件:sudo apt upgrade
  2. 性能优化

    • WireGuard 更适合移动设备(低延迟)。
    • OpenVPN 兼容性更广(支持 TCP 模式)。
  3. 故障排查

    • 检查日志:journalctl -u wg-quick@wg0tail -f /var/log/syslog
    • 测试连通性:ping 10.0.0.1(服务端内网 IP)。

选择 WireGuard 更轻量,适合个人使用;OpenVPN 则适合企业复杂场景,根据需求选择即可!

WireGuard

转载请注明来自快连加速器下载-下载快连 - 全平台客户端 | 高速安全网络连接 | 快连官网,本文标题:《WireGuard》

每一天,每一秒,你所做的决定都会改变你的人生!