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"}'

参考文档

相关推荐
Victor35610 小时前
https://editor.csdn.net/md/?articleId=139321571&spm=1011.2415.3001.9698
后端
Victor35610 小时前
Hibernate(89)如何在压力测试中使用Hibernate?
后端
灰子学技术11 小时前
go response.Body.close()导致连接异常处理
开发语言·后端·golang
Gogo81612 小时前
BigInt 与 Number 的爱恨情仇,为何大佬都劝你“能用 Number 就别用 BigInt”?
后端
fuquxiaoguang12 小时前
深入浅出:使用MDC构建SpringBoot全链路请求追踪系统
java·spring boot·后端·调用链分析
毕设源码_廖学姐13 小时前
计算机毕业设计springboot招聘系统网站 基于SpringBoot的在线人才对接平台 SpringBoot驱动的智能求职与招聘服务网
spring boot·后端·课程设计
野犬寒鸦14 小时前
从零起步学习并发编程 || 第六章:ReentrantLock与synchronized 的辨析及运用
java·服务器·数据库·后端·学习·算法
逍遥德15 小时前
如何学编程之01.理论篇.如何通过阅读代码来提高自己的编程能力?
前端·后端·程序人生·重构·软件构建·代码规范
MX_935916 小时前
Spring的bean工厂后处理器和Bean后处理器
java·后端·spring
程序员泠零澪回家种桔子17 小时前
Spring AI框架全方位详解
java·人工智能·后端·spring·ai·架构