OpenWrt 软件源配置
1.概述
1.1 介绍
OpenWrt官方软件源有时会失效或者地区原因无法连接,所以需要更换到国内的软件源,这样能更快的访问和下载到所以需要的软件。
[!TIP]
从 OpenWrt 25.12 开始,包管理器由opkg 改为apk (Alpine Package Keeper) ,默认软件源的配置文件路径由/etc/opkg/distfeeds.conf 改为/etc/apk/repositories.d/distfeeds.list。
1.2 环境
当前的使用系统版本为:OpenWrt 25.12.2,以下将以此版本作为示例,不同版本的系统需注意使用对应源地址。
OpenWrt 当前仍在维护的大版本可参考:https://openwrt.org/mirrors#space_requirements
[!TIP]
访问 snapshots 与 RC 版本内容会重定向至反向代理,如果需要下载相关文件,务必使用 HTTPS,否则连接可能会被中断。访问 https://mirrors.ustc.edu.cn/lede/ 会被自动重定向到 https://mirrors.ustc.edu.cn/openwrt/。
1.3 文件
在OpenWrt系统中,软件源地址为:/etc/opkg/distfeeds.conf,使用如下命苦修改配置文件:
vim /etc/opkg/distfeeds.conf
2.地址
2.1 清华源
清华源站点提供 OpenWRT 的包管理器 opkg 的 release 部分镜像,但本站不包含 snapshots 镜像,如果需要 snapshots,可以前往校园网联合镜像站寻找替代。
清华源站点地址:
# 中科大源站点的帮助站点
https://mirror.tuna.tsinghua.edu.cn/help/openwrt/
# 中科大源地址
https://mirrors.tuna.tsinghua.edu.cn/openwrt
2.2 中科大源
部分镜像站(例如 TUNA/BFSU)并不包含 snapshots 镜像,USTC 提供了对 snapshots 的反代,请在替换之前确认各镜像站的情况。
中科大源站点地址:
# 中科大源站点的帮助站点
https://mirrors.ustc.edu.cn/help/openwrt.html
# 中科大源地址
https://mirrors.ustc.edu.cn/openwrt
2.4. 其他
更多的OpenWRT 软件仓库源可以参考MirrorZ Project站点,可以参考地址如下:
https://help.mirrors.cernet.edu.cn/openwrt/
3.替换
对于 OpenWrt 25.12 及以上版本,需选择 APK;对于 OpenWrt 24.10 及以下版本,需选择 OPKG。
3.1 自动替换
对于APK包管理器的系统,使用如下命令(使用清华源做示例),以进行自动替换:
# 清华源
sed -i 's_https\?://downloads.openwrt.org_https://mirrors.tuna.tsinghua.edu.cn/openwrt_' /etc/apk/repositories.d/distfeeds.list
# 中科大源
sed -i 's/downloads.openwrt.org/mirrors.ustc.edu.cn\/openwrt/g' /etc/apk/repositories.d/distfeeds.list
对于OPKG包管理器的系统,使用如下命令,以进行自动替换:
# 清华源
sed -i 's_https\?://downloads.openwrt.org_https://mirrors.tuna.tsinghua.edu.cn/openwrt_' /etc/opkg/distfeeds.conf
# 中科大源
sed -i 's/downloads.openwrt.org/mirrors.ustc.edu.cn\/openwrt/g' /etc/opkg/distfeeds.conf
[!NOTE]
注:使用 HTTPS 可以有效避免国内运营商的缓存劫持,但需要另行安装 libustream-openssl ca-bundle ca-certificates。
3.2 手动替换
登录到路由器,根据版本或包管理器选择编辑 /etc/apk/repositories.d/distfeeds.list 或 /etc/opkg/distfeeds.conf 文件。
一般情况下,原始下载来自 downloads.openwrt.org 地址,将 URL 中的这部分域名替换为 mirrors.ustc.edu.cn/openwrt 或其他源地址即可,如下为源地址:
# 清华源
https://mirrors.tuna.tsinghua.edu.cn/openwrt
# 中科大源
https://mirrors.ustc.edu.cn/openwrt
然后重新使用update刷新下缓存:
# APK 包管理
apk update
# OPKG 包管理
opkg update