openwrt 开发 环境配置 版本选择 基础知识

openwrt 开发 环境配置 版本选择 基础知识

openwrt 和 immortalwrt:openwrt 最新版本24.10,纯官方作品,非常干净,默认配置什么也没有 luci 也没有选中。immortalwrt 是中文社区版,目前更新还很活跃,支持的型号比较多,硬件支持更新较快,主代码仓库基本和openwrt 更新保持一致。默认有打开了很多常用配置,luci 中文翻译等。而且有很多提交也是中文写的。 https://github.com/openwrt/openwrthttps://github.com/immortalwrt/immortalwrt

基本的组件:ubus rpc 跨进程调用,类似于 linux 的dbus、安卓的 Binderuci 配置管理工具luci 基于 lua 的 uci

开发环境:ubuntu 25.10 + docker对于,只开发应用使用 docker 是最好的选择,测试验证速度快,也不需要刷机。配置工作在旁路由模式即可。

配置 Target System 选中 x86 并选择生成 rootfs 镜像

make menuconfig

Target System (x86)

Target Images --->

[*] tar.gz

*** Root filesystem images ***

编译完成,生成的文件

ls bin/targets/x86/generic/

config.buildinfo openwrt-x86-generic-generic-kernel.bin openwrt-x86-generic-generic-squashfs-rootfs.img.gz

feeds.buildinfo openwrt-x86-generic-generic.manifest packages

openwrt-x86-generic-generic-ext4-combined-efi.img.gz openwrt-x86-generic-generic-rootfs.tar.gz profiles.json

openwrt-x86-generic-generic-ext4-combined.img.gz openwrt-x86-generic-generic-squashfs-combined-efi.img.gz sha256sums

openwrt-x86-generic-generic-ext4-rootfs.img.gz openwrt-x86-generic-generic-squashfs-combined.img.gz version.buildinfo

使用 docker 将编译出来的 rootfs 导入为 image 镜像

docker import openwrt-x86-generic-generic-rootfs.tar.gz openwrt-x86-generic-rootfs

docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

openwrt-x86-generic-rootfs latest 0cbcf6dc7160 4 seconds ago 13.9MB

查看宿主电脑网卡和网段

ens33: flags=4163 mtu 1500

inet 192.168.141.160 netmask 255.255.255.0 broadcast 192.168.141.255

ip route show

default via 192.168.141.2 dev ens33 proto dhcp metric 100

ip link set ens33 promisc on

创建 docker 网络

docker network create -d macvlan \

--subnet=192.168.141.0/24 --gateway=192.168.141.1 \

--ipv6 --subnet=fe80::/16 --gateway=fe80::1 \

-o parent=ens33 \

-o macvlan_mode=bridge \

macvlan

启动镜像

docker run --restart always --name openwrt -d --network macvlan --privileged openwrt-x86-generic-rootfs /sbin/init

解决宿主机与容器通信问题

sudo ip link add host-macvlan link ens33 type macvlan mode bridge

# 分配 IP(需与容器同网段但不同地址)

sudo ip addr add 192.168.141.99/24 dev host-macvlan

# 启用接口

sudo ip link set host-macvlan up

进入容器

docker exec -it openwrt ash

配置IP

vi /etc/config/network

config interface 'loopback'

option device 'lo'

option proto 'static'

option ipaddr '127.0.0.1'

option netmask '255.0.0.0'

config globals 'globals'

option ula_prefix 'fd27:606b:47fd::/48'

config device

option name 'br-lan'

option type 'bridge'

list ports 'eth0'

config interface 'lan'

option device 'br-lan'

option proto 'static'

option ipaddr '192.168.1.1'

option netmask '255.255.255.0'

option ip6assign '60'

lan 修改为

config interface 'lan'

option type 'bridge'

option ifname 'eth0'

option proto 'static'

option ipaddr '192.168.141.111'

option netmask '255.255.255.0'

option ip6assign '60'

option gateway '192.168.141.2'

option dns '192.168.141.2 223.5.5.5'

重启网络服务

/etc/init.d/network restart

在宿主 通过 ssh 登录

ssh root@192.168.141.111

The authenticity of host '192.168.141.111 (192.168.141.111)' can't be established.

ED25519 key fingerprint is SHA256:63GYGK+otfqSlK1VzJqPzvK4Rxj6cJjKBe1dmE1WsX8.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.141.111' (ED25519) to the list of known hosts.

BusyBox v1.36.1 (2025-11-22 22:04:43 UTC) built-in shell (ash)

_______ ________ __

| |.-----.-----.-----.| | | |.----.| |_

| - || _ | -__| || | | || _|| _|

|_______|| __|_____|__|__||________||__| |____|

|__| W I R E L E S S F R E E D O M

-----------------------------------------------------

OpenWrt 24.10-SNAPSHOT, r28899-8554e22ace

-----------------------------------------------------

=== WARNING! =====================================

There is no root password defined on this device!

Use the "passwd" command to set up a new password

in order to prevent unauthorized SSH logins.

--------------------------------------------------

root@OpenWrt:~#

WEB控制界面开发:现在 24版本,WEB使用 JS 语言开发,对于会前端开发的人来说,学习非常容易。

更新 ubuntu 25.10 openwrt 24.10 检查出错 Please install GNU 'install' :命令本来是有的,可能是换了版本没有 GNU 关键字,把这个检查删除即可。

diff --git a/include/prereq-build.mk b/include/prereq-build.mk

index 8b138cfc44..f9e0e308e0 100644

--- a/include/prereq-build.mk

+++ b/include/prereq-build.mk

@@ -174,10 +174,6 @@ $(eval $(call SetupHostCommand,bzip2,Please install 'bzip2', \

$(eval $(call SetupHostCommand,wget,Please install GNU 'wget', \

wget --version | grep GNU))

-$(eval $(call SetupHostCommand,install,Please install GNU 'install', \

- install --version | grep GNU, \

- ginstall --version | grep GNU))

-

$(eval $(call SetupHostCommand,perl,Please install Perl 5.x, \

perl --version | grep "perl.*v5"))

相关推荐

网易游戏团队宣布《黎明杀机》手游 2025 年 3 月 20 日停服
十大世界杯打架事件(鲜血与红牌飞舞,十大世界杯历史上的打架事件)
游戏开发需要学什么?掌握这5大核心技能,让你成为游戏界的佼佼者!