获取所有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"}'