OpenWRT ubus使用uci修改配置

获取所有config

使用ubus call uci configs命令

sh 复制代码
~# ubus call uci configs
{
	"configs": [
		"dhcp",
		"dropbear",
		"firewall",
		"fstab",
		"luci",
		"network",
		"nginx",
		"openssl",
		"rpcd",
		"system",
		"uhttpd",
	]
}

查看某一个config下的所有section

使用ubus call uci get '{"config": "network"}'命令, 我们查看network下的所有配置,其中返回结果中的loopback,globals, cfg030f15, lan, wan, wan6称为section(章节)

sh 复制代码
~# ubus call uci get '{"config": "network"}'
{
	"values": {
		"loopback": {
			".anonymous": false,
			".type": "interface",
			".name": "loopback",
			".index": 0,
			"device": "lo",
			"proto": "static",
			"ipaddr": "127.0.0.1",
			"netmask": "255.0.0.0"
		},
		"globals": {
			".anonymous": false,
			".type": "globals",
			".name": "globals",
			".index": 1,
			"ula_prefix": "fd8b:f653:d00b::/48"
		},
		"cfg030f15": {
			".anonymous": true,
			".type": "device",
			".name": "cfg030f15",
			".index": 2,
			"name": "br-lan",
			"type": "bridge",
			"ports": [
				"eth0"
			]
		},
		"lan": {
			".anonymous": false,
			".type": "interface",
			".name": "lan",
			".index": 3,
			"device": "br-lan",
			"proto": "static",
			"ipaddr": "192.168.146.147",
			"netmask": "255.255.255.0",
			"ip6assign": "60"
		},
		"wan": {
			".anonymous": false,
			".type": "interface",
			".name": "wan",
			".index": 4,
			"device": "eth1",
			"proto": "dhcp"
		},
		"wan6": {
			".anonymous": false,
			".type": "interface",
			".name": "wan6",
			".index": 5,
			"device": "eth1",
			"proto": "dhcpv6"
		}
	}
}

获取某一section下设备的信息

使用ubus call uci get '{"config":"network","section":"lan"}'命令,我们使用这个命令查看lan章节下的设备信息

sh 复制代码
~# ubus call uci get '{"config":"network","section":"lan"}'
{
	"values": {
		".anonymous": false,
		".type": "interface",
		".name": "lan",
		"device": "br-lan",
		"proto": "static",
		"ipaddr": "192.168.146.146",
		"netmask": "255.255.255.0",
		"ip6assign": "60"
	}
}

修改设备的IP地址

我们使用如下命令将network下的lan章节的ip地址设置为新的ip.

sh 复制代码
ubus call uci set '{"config":"network","section":"lan","values":{"ipaddr": "192.168.146.147"}}'

设置完后不会立即生效,我们需要提交一下使我们刚才的修改生效

sh 复制代码
ubus call uci commit '{"config":"network"}'

删除某个section的配置

下面的命令中我们删除了lan章节下的ipaddr配置。

sh 复制代码
 ubus call uci delete '{"config":"network","section":"lan","option":"ipaddr"}'

设置完后不会立即生效,我们需要提交一下使我们刚才的修改生效

sh 复制代码
ubus call uci commit '{"config":"network"}'

删除某个section的多个配置

下面的命令中我们删除了lan章节下的ipaddr, gateway配置。

sh 复制代码
ubus call uci delete '{"config":"network","section":"lan","option":["ipaddr","gateway"]}'

设置完后不会立即生效,我们需要提交一下使我们刚才的修改生效

sh 复制代码
ubus call uci commit '{"config":"network"}'

参考文档

相关推荐
追逐时光者6 小时前
精选 4 款基于 .NET 开源、功能强大的 Windows 系统优化工具
后端·.net
TF男孩6 小时前
ARQ:一款低成本的消息队列,实现每秒万级吞吐
后端·python·消息队列
AAA修煤气灶刘哥7 小时前
别让Redis「歪脖子」!一次搞定数据倾斜与请求倾斜的捉妖记
redis·分布式·后端
AAA修煤气灶刘哥8 小时前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql
你的人类朋友8 小时前
什么是API签名?
前端·后端·安全
昵称为空C10 小时前
SpringBoot3 http接口调用新方式RestClient + @HttpExchange像使用Feign一样调用
spring boot·后端
架构师沉默10 小时前
设计多租户 SaaS 系统,如何做到数据隔离 & 资源配额?
java·后端·架构
RoyLin11 小时前
TypeScript设计模式:适配器模式
前端·后端·node.js
该用户已不存在11 小时前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
Moonbit11 小时前
MoonBit 正式加入 WebAssembly Component Model 官方文档 !
前端·后端·编程语言