OpenWrt

闲置树莓派 5 放着也是吃灰,于是拿来装 OpenWrt 系统

Prerequisite

  • 树莓派 5 开发板
  • MicroSD 卡,建议 32GB 及其以上
  • 网线(用于初始配置)
  • 读卡器
  • 电源适配器(USB-C接口)

下载 OpenWrt 固件

进入官方页面 OpenWrt Firmware Selector 选择所需要的树莓派 5 的固件,稳定版以 YY.MM.x 的形式,开发板则标为 snapshot。此处我选择 snapshot 版本。

OpenWrt Firmware Selector

若需定制 package 或添加首次启动脚本,则选择 "Customize installed packages and/or first boot script",选择安装的 packages,最后再 "request build"

以下脚本为示例

#!/bin/sh

# OpenWrt first boot network configuration script
# This script will modify the default network settings

# Set LAN interface IP address to 192.168.0.254
uci set network.lan.ipaddr='192.168.0.254'

# Set netmask to 255.255.255.0 (default /24 subnet)
uci set network.lan.netmask='255.255.255.0'

# Set gateway to 192.168.0.1
uci set network.lan.gateway='192.168.0.1'

# Set DNS server to 192.168.0.1
uci set network.lan.dns='192.168.0.1'

# Configure DHCP to provide upstream DNS to clients
uci set dhcp.lan.dhcp_option='6,192.168.1.1'

# Commit the configuration changes
uci commit network
uci commit dhcp

# Exit successfully
exit 0

下载后文件名为 openwrt-bcm27xx-bcm2712-rpi-5-ext4-factory.img.gzopenwrt-xxxxxx-bcm27xx-bcm2712-rpi-5-ext4-factory.img.gz

写入固件至 SD 卡中

打开 Raspberry Pi Imager,选择下载的 OpenWrt 固件镜像文件,选择 SD 卡作为目标设备,开始写入过程,等待完成。

Rasberry Pi Imager上将固件刷入到SD卡中

选择 "Next",不应用设定,选择 "No"

选择不应用设定

确定格式化数据

格式化SD卡上数据

等待片刻完成后,取出 SD 卡插入到树莓派上。

首次启动并配置网络

OpenWrt 设置默认 IP 为 192.168.1.1,为避免与光猫 IP 冲突,断开其它网络连接,将树莓派连接网线至电脑/笔记本上,插入电源启动设备

将树莓派通过网线连接到笔记本上

SSH 连接至 192.168.1.1,初次连接默认无密码,需通过 passwd 更改 root 密码

连接 SSH

在树莓派上修改网络配置,添加默认网关和DNS


config interface 'loopback'
        option device 'lo'
        option proto 'static'
        list ipaddr '127.0.0.1/8'

config globals 'globals'
        option ula_prefix 'fdcf:2cca:6361::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        list ipaddr '192.168.0.150/24'
        option gateway '192.168.0.1'
        list dns '192.168.0.1'
        option ip6assign '60'

然后 service network restart 重启并更新网络配置。

参考资料

通过OpenWrt官方构建自定义固件 | 搬砖人

最后修改:2025 年 07 月 04 日
如果觉得我的文章对你有用,请随意赞赏