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

参考文档

相关推荐
大阿明17 小时前
Spring Boot(快速上手)
java·spring boot·后端
墨香幽梦客18 小时前
API集成技术规范:RESTful与GraphQL在企业系统对接中的应用对比
后端·restful·graphql
刀法如飞19 小时前
AI编程时代,为什么35岁以上程序员会更吃香?
人工智能·后端·ai编程
小码哥_常19 小时前
Spring Boot 遇上 HMAC-SHA256,API 安全大升级!
后端
小码哥_常19 小时前
10分钟极速掌握!SpringBoot+Vue3整合SSE实现实时消息推送
后端
大黄说说20 小时前
深入 Go 语言 GMP 调度模型:高并发的秘密武器
后端
云原生指北21 小时前
Omnipub E2E 测试文章 - 自动化验证
后端
IT_陈寒21 小时前
SpringBoot自动配置揭秘:5个让开发效率翻倍的隐藏技巧
前端·人工智能·后端
添尹1 天前
Go语言基础之数组
后端·golang
luom01021 天前
SpringBoot - Cookie & Session 用户登录及登录状态保持功能实现
java·spring boot·后端