Skip to content

📒 代理与虚拟专用网

代理

VPN

WireGuard

  • 基本原理:

    • 无连接
    • 握手过程:

      sequenceDiagram
          participant A as initiator
          participant B as responder
          A->>B: handshake initiation
          B->>A: handshake response
          Note over A,B: keys calculated
          A<<->>B: secure data exchange
    • 发包过程:

      1. 根据 IP 地址寻找 Peer,否则丢弃。
      2. 加密。
      3. 寻找 Peer 的 Remote Endpoint。
      4. 发包。
    • 收包过程:
      1. 解密。
      2. 认证 Peer 信息,成功则更新 Peer Endpoint。
      3. 检查 Peer 是否被允许以对应的 IP 地址发送数据。
      4. 收包。
  • 配置:

    Warning

    wg 命令和 wg-quick 命令的配置文件格式不同。下面为 wg-quick 的配置文件。

    wg-quick up wg0
    
    /etc/wireguard/wg0.conf
    [Interface]
    Address = 
    ListenPort = 
    PrivateKey = 
    MTU = # 如有 L2TP 等隧道服务可能需要调整 MTU
    
    [Peer]
    PublicKey = 
    Endpoint = 
    AllowedIPs = 
    PersistentKeepalive = # 如 NAT 环境较差可设置 PersistentKeepalive 保持连接
    
  • 调测: