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 分钟前
k8s常用总结
运维·后端·k8s
TheITSea29 分钟前
后端开发 SpringBoot 工程模板
spring boot·后端
Asthenia041231 分钟前
编译原理中的词法分析器:从文本到符号的桥梁
后端
Asthenia04121 小时前
用RocketMQ和MyBatis实现下单-减库存-扣钱的事务一致性
后端
Pasregret1 小时前
04-深入解析 Spring 事务管理原理及源码
java·数据库·后端·spring·oracle
Micro麦可乐1 小时前
最新Spring Security实战教程(七)方法级安全控制@PreAuthorize注解的灵活运用
java·spring boot·后端·spring·intellij-idea·spring security
returnShitBoy1 小时前
Go语言中的defer关键字有什么作用?
开发语言·后端·golang
Asthenia04121 小时前
面试场景题:基于Redisson、RocketMQ和MyBatis的定时短信发送实现
后端
Asthenia04122 小时前
链路追踪视角:MyBatis-Plus 如何基于 MyBatis 封装 BaseMapper
后端
Ai 编码助手2 小时前
基于 Swoole 的高性能 RPC 解决方案
后端·rpc·swoole