路由器OpenWrt固件-软件包问题
-柒阁
2025年11月06日 19:14

opkg update 命令失败,返回错误代码 6

-通常意味着 网络连接问题 或 软件源配置错误。默认情况下,OpenWrt 使用国外的源进行软件包的下载和更新,这在中国境内可能会遇到下载速度慢、连接不稳定等问题。

一,可能原因

1.网络连接不稳定或者不可用

  • 路由器无法访问互联网

  • 防火墙、代理设置阻止对软件源的访问

2.软件源地址错误

  • /etc/opkg/distfeeds.conf 或 /etc/opkg/base-feeds.conf 中的 URL 错误

  • 软件源服务器已下线或被移除

3.DNS解析问题

  • 无法解析软件源域名

二,解决办法

1. 检查网络连接

首先,确保你的设备能够访问互联网。你可以通过 ping 命令来测试连接。

ping www.baidu.com

如果无法 ping 通,请检查路由器的网关和 DNS 设置。

2. 更改 DNS 设置 有时,DNS 配置不正确会导致无法下载包列表。你可以编辑 /etc/resolv.conf 文件,将 nameserver 设置为公共 DNS,如 8.8.8.8 和 8.8.4.4。 echo "nameserver 8.8.8.8" > /etc/resolv.conf echo "nameserver 8.8.4.4" >> /etc/resolv.conf 3. 删除 wget-nossl 包 如果固件默认安装了 wget-nossl,它可能无法处理 HTTPS 链接。删除 wget-nossl 并安装 wget-ssl。 opkg remove wget-nossl opkg install wget-ssl 4. 更换软件源

如果以上方法无效,可以尝试更换软件源。编辑 /etc/opkg/customfeeds.conf 文件,替换为其他可用的镜像源。

OpenWrt的OPKG命令软件源的配置文件有以下两个:

/etc/opkg/customfeeds.conf:

    用户自定义源,建议把新增的软件源写在该文件中,格式为:src/gz 源名称 源地址

/etc/opkg/distfeeds.conf:

    发行版官方源,不建议更改,如果替换了同名称的源,可以将其内容注释掉以便恢复。

customfeeds替换为中科大、清华镜像源

方案一:

    1.先将 /etc/opkg/distfeeds.conf 中的所有条目复制到 /etc/opkg/customfeeds.conf 中,然后注释掉 distfeeds.conf 中的内容。

    2.再将 customfeeds.conf 文件中的 http://downloads.openwrt.org/ 替换为 https://mirrors.ustc.edu.cn/lede/ 或者 https://mirrors.tuna.tsinghua.edu.cn/openwrt/ 即可。

方案二:

    sed -i 's_downloads.openwrt.org_mirrors.tuna.tsinghua.edu.cn/openwrt_' /etc/opkg/distfeeds.conf

由于很多源是https,所以需要安装curl的ssl支持,命令如下:

opkg update

opkg install libustream-openssl ca-bundle ca-certificates

kwrt 24.10默认配置文件如下

src/gz kwrt_core https://dl.openwrt.ai/releases/24.10/targets/mediatek/filogic/6.6.92

src/gz kwrt_base https://dl.openwrt.ai/releases/24.10/packages/aarch64_cortex-a53/base

src/gz kwrt_packages https://dl.openwrt.ai/releases/24.10/packages/aarch64_cortex-a53/packages

src/gz kwrt_luci https://dl.openwrt.ai/releases/24.10/packages/aarch64_cortex-a53/luci

src/gz kwrt_routing https://dl.openwrt.ai/releases/24.10/packages/aarch64_cortex-a53/routing

src/gz kwrt_kiddin9 https://dl.openwrt.ai/releases/24.10/packages/aarch64_cortex-a53/kiddin9

OpenWrt 24.10.0-rc5修改国内源后配置文件如下

src/gz openwrt_core https://mirrors.tencent.com/lede/releases/24.10.0-rc5/targets/x86/64/packages

src/gz openwrt_base https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/packages-24.10/x86_64/base

src/gz openwrt_packages https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/packages-24.10/x86_64/packages

src/gz openwrt_luci https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/packages-24.10/x86_64/luci

src/gz openwrt_routing https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/packages-24.10/x86_64/routing

src/gz openwrt_telephony https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/packages-24.10/x86_64/telephony

国内各大OpenWrt 镜像源

1. 清华大学开源软件镜像站

  • 镜像地址: https://mirrors.tuna.tsinghua.edu.cn/openwrt/

2. 阿里云开源镜像站

  • 镜像地址: https://mirrors.aliyun.com/openwrt/

3. 中科大开源软件镜像站

  • 镜像地址: https://mirrors.ustc.edu.cn/openwrt/

4. 网易开源镜像站

  • 镜像地址: https://mirrors.163.com/openwrt/