UCI command system

1 UCI command

A well-known reasons, the various software packages under Linux have a variety of different configuration script, different syntax and operation of each configuration script, although this design can reflect their own advantages in each package, while also increasing learning curve. At this point, the UCI OpenWrt undoubtedly treated better. UCI is the abbreviation for centralized configuration management interface (Unified Configuration Interface), he is the introduction of a set of configuration parameters OpenWrt management systems. UCI management of human-computer interaction interface to the main system configuration parameters and provides a simple, easy, standardized under OpenWrt. UCI already contains main configuration parameters of the network configuration, wireless configuration, system configuration information and the like required for a basic router. Meanwhile UCI can also help developers quickly build a set of intelligent routing products based on OpenWrt control interface.

2 UCI documents and processes

UCI configuration files are all stored in the / etc / config directory.

root@OpenWrt:/# ls /etc/config/
dhcp            dropbear    firewall    network      system        wireless

There is a substantial package supports the UCI management mode, but not all packages, support packages is to complete the startup (to samba for example):
1) the startup script /etc/init.d/samba
2). startup script obtained by the UCI analysis libraries from / etc / config / samba startup parameter
3). startup script to complete the normal startup

Since the data file UCI relatively simple and have a very nice direct perception, the configuration file may be used to modify the command UCI, VI editor may be used to modify the file directly. But note that if the UCI command are two ways to use changes will produce the cache, each modification good save to confirm as soon as possible to avoid conflict.

The most common of several UCI configured role Description:

file effect
/etc/config/dhcp IP address for the LAN port distribution service provided by the configuration
/etc/config/dropbear SSH service configuration
/etc/config/firewall Routing and forwarding, port forwarding, firewall rules
/etc/config/network Own network interface configuration
/etc/config/system Time Server time zone configuration
/etc/config/wireless Wireless Network Configuration

3 UCI's file syntax

UCI file syntax examples:

config 'section-type' 'section'
        option  'key'       'value'
        list    'list_key'  'list_value'
        
config 'example' 'test'
        option  'string'        'some value'
        option  'boolean'       '1'
        list    'collection'    'first item'
        list    'collection'    'second item'

config			节点,以关键字 config 开始的一行用来代表当前节点
section-type	节点类型
section			节点名称

option			选项,表示节点中的一个元素
key 			键
value 			值

list 			列表选项,表示列表形式的一组参数。
list_key 		列表键
list_value 		列表值

config node syntax:

config 'section-type' 'section'
config 节点(后文统一称为节点)原则
 - UCI 允许只有节点类型的匿名节点存在
 - 节点类型和名字建议使用单引号包含以免引起歧义
 - 节点中可以包含多个 option 选项或 list 列表选项。
 - 节点遇到文件结束或遇到下一个节点代表完成。

option option syntax:

option 'key' 'value'
option 选项(后文统一称为选项)原则
 - 选项的键与值建议使用单引号包含
 - 避免相同的选项键存在于同一个节点,否则只有一个生效

list list of options syntax:

list 'list_key' 'list_value'
list 列表选项(后文统一称为列表)原则
 - 选项的键与值建议使用单引号包含
 - 列表键的名字如果相同,则相同键的值将会被当作数组传递给相应软件

UCI syntax fault tolerance:

option example    value
option 'example'   value
option example    "value"
option "example"  'value'
option 'example'   "value"

UCI intolerable syntax:

option 'example" "value'
option example some value with space

Try to use the regular characters to processor UCI, there are special characters could undermine the integrity of the data structure.

4 UCI configuration read command

Syntax:

uci [<options>] <command> [<arguments>]

Reading and writing rules:

  • UCI read is always read before memory cache, and then read the file
  • Been add, modify, delete operations to be performed after the entry into force of the instruction, otherwise your modifications only remain in the cache

1. Read class syntax

Get node type:

uci get <config>.<section>

To obtain a value of:

uci get <config>.<section>.<option>

All UCI configuration:

uci show

Displays the specified configuration file:

uci show <config>

Displays the name of the node configuration:

uci show <config>.<section>

Displays the configuration options:

uci show <config>.<section>.<option>

Display modify records not yet in force:

uci changes <config>

Display anonymous node (if the node content displayed anonymity, the -X parameter may exhibit an anonymous node ID):

uci show -X <config>.<section>.<option>

2. Write class syntax

Add a node to file anonymous:

uci add <config> <section-type>

Add a node to the file:

uci set <config>.<section>=<section-type>

And an option to increase the value of node:

uci set <config>.<section>.<option>=<value>

Add a value to the list:

uci add_list <config>.<section>.<option>=<value>

Modify a node of the type:

uci set <config>.<section>=<section-type>

Modify the value of an option:

uci set <config>.<section>.<option>=<value>

Removes the specified node name:

uci delete <config>.<section>

Deletes the specified options:

uci delete <config>.<section>.<option>

Delete the list:

uci delete <config>.<section>.<list>

To delete a value list:

uci del_list <config>.<section>.<option>=<string>

Take effect modification (of any kind of written grammar, and ultimately have to perform modifications to take effect, otherwise your modifications only in the cache, remember!):

uci commit <config>

5 Examples

1, export the entire configuration
Here Insert Picture Description
2, see the values of all configuration items
Here Insert Picture Description
3, view the value of a specific configuration item
Here Insert Picture Description
4, query the status of the network interface
Here Insert Picture Description
5, add firewall rules

This is a port to forward SSH examples firewall rules, and "-1" used to add one example.
Here Insert Picture Description
note:

To get the value (setting empathy) option, the two cases, make an explanation here:

Configuration file / etc / config / demo, as follows:
Here Insert Picture Description
1, the case where the name of the node. You can obtain the following command:

uci get <configFileName>.<sectionName>.optionName

Such as:

uci get demo.test1.op1			//获取到的值为123
uci get demo.bind.bindip		//获取到的值为192.168.1.124

2, node name is not the case. We need to get through the following command:

uci get <configFileName>.@<sectionType>[N].optionName

Such as:

uci get demo.@ssr[-1].server	//获取到的值为1.2.3.8,-1代表最后一个配置
uci get demo.@ssr[0].server		//获取到的值为1.2.3.4,0代表第一个配置
uci get demo.@ssr[1].server		//获取到的值为1.2.3.5,1代表第二个配置
uci get demo.@ssr[2].server		//获取到的值为1.2.3.6,2代表第三个配置
uci get demo.@ssr[3].server		//获取到的值为1.2.3.7,3代表第四个配置
uci get demo.@ssr[4].server		//获取到的值为1.2.3.8,4代表第五个配置

If the cases where only one configuration, the subscripts 1 and 0 obtained is the same value.

Published 21 original articles · won praise 11 · views 20000 +

Guess you like

Origin blog.csdn.net/hexf9632/article/details/100893086