Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

如何在openwrt上设置wireguard vpn

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-pro’s answer.
  1. User

    如何在openwrt上设置wireguard vpn

  2. Assistant

    在 OpenWrt 上设置 WireGuard VPN 主要分为以下几个步骤:


    1. 安装 WireGuard

    首先,确保你的 OpenWrt 路由器已经联网,然后通过 SSH 登录到路由器,执行以下命令安装 WireGuard 相关软件包:

    opkg update
    opkg install wireguard-tools luci-app-wireguard
    
    • wireguard-tools:WireGuard 的核心工具。
    • luci-app-wireguard:Web 管理界面(可选,但推荐)。

    2. 生成密钥对

    在路由器上生成 WireGuard 的公钥和私钥:

    umask 077
    wg genkey | tee privatekey | wg pubkey > publickey
    
    • privatekey 文件保存私钥
    • publickey 文件保存公钥

    3. 配置 WireGuard 接口

    方法一:通过 Web 界面(LuCI)

    1. 登录 OpenWrt 的 Web 管理界面(LuCI)。

    2. 进入 网络 > WireGuard。

    3. 点击 添加,填写如下信息:

      • 名称:如 wg0
      • 私钥:填入刚才生成的 privatekey 内容
      • 监听端口:如 51820(默认 WireGuard 端口)
      • IP 地址:如 10.0.0.1/24(自定义内网段)
    4. 添加 Peer(对端)信息:

      • 公钥:对端设备的公钥
      • 允许的 IP:如 10.0.0.2/32(对端分配的 IP)
      • 端点主机:对端的公网 IP:端口(如有需要)
      • 预共享密钥:可选

    方法二:通过命令行配置

    编辑 /etc/config/network,添加如下内容:

    config interface 'wg0'
        option proto 'wireguard'
        option private_key '你的私钥'
        option listen_port '51820'
        list addresses '10.0.0.1/24'
    
    config wireguard_wg0
        option public_key '对端公钥'
        option description 'peer1'
        list allowed_ips '10.0.0.2/32'
    

    4. 配置防火墙

    编辑 /etc/config/firewall,添加 WireGuard 端口到允许列表:

    config rule
        option name 'Allow-WireGuard-Inbound'
        option src 'wan'
        option dest_port '51820'
        option proto 'udp'
        option target 'ACCEPT'
    

    重启防火墙:

    /etc/init.d/firewall restart
    

    5. 启用并启动 WireGuard

    /etc/init.d/network restart
    

    或者在 LuCI 界面点击“保存并应用”。


    6. 配置客户端

    在你的客户端(如手机、电脑)上安装 WireGuard,添加配置:

    [Interface]
    PrivateKey = 客户端私钥
    Address = 10.0.0.2/24
    
    [Peer]
    PublicKey = 路由器公钥
    Endpoint = 路由器公网IP:51820
    AllowedIPs = 0.0.0.0/0, ::/0
    

    7. 测试连接

    在客户端连接 WireGuard,检查是否能访问路由器和互联网。


    常见问题

    • 端口未开放:确认路由器 WAN 口已开放 51820 UDP 端口。
    • 密钥错误:确保公钥、私钥填写无误。
    • 路由问题:确认 AllowedIPs 配置正确。

    如需更详细的配置(如全局代理、分流等),可补充说明你的需求!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.