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

参考文档

相关推荐
程序员葵安1 小时前
【苍穹外卖项目】Day05
spring boot·后端
Code blocks7 小时前
关于“LoggerFactory is not a Logback LoggerContext but Logback is on ......“的解决方案
java·spring boot·后端
04Koi.9 小时前
八股训练--Spring
java·后端·spring
Livingbody11 小时前
【心理咨询师数字孪生对话数据集】标准化为 ShareGPT OpenAI 格式
后端
AQin101212 小时前
IP 🆚 MAC,你分得清吗?
后端·网络协议
天涯学馆13 小时前
Solidity 中的高级模式匹配:提升代码的可读性和可维护性
后端·区块链·solidity
郝学胜-神的一滴13 小时前
Spring Boot Actuator 保姆级教程
java·开发语言·spring boot·后端·程序人生
剪刀石头布啊14 小时前
数据口径
前端·后端·程序员
剪刀石头布啊14 小时前
http状态码大全
前端·后端·程序员
jiangxia_102414 小时前
面试系列:什么是JAVA并发编程中的JUC并发工具类
java·后端