← All posts

OpenWrt UCI: config files, commands, and boundaries

Grow through practice

No need to finish reading — test now

One line: UCI is OpenWrt's configuration layer: a unified file format plus read/write commands. It does not apply configuration, and it is not a runtime data model.

This article covers UCI itself. For UCI's boundaries and why prplOS adds a data-model layer on top, see “From UCI to a data model: what prplOS improved, and why it is necessary”.

What it manages

UCI centralizes each daemon's config file under /etc/config/<package>:

config interface 'wan'
    option proto 'dhcp'
    option metric '10'
    list dns '1.1.1.1'
    list dns '8.8.8.8'

Three levels:

  • package: one config file, e.g. network, firewall, wireless;
  • section: config <type> '<name>', e.g. config interface 'wan';
  • option / list: a single value / multiple values.

A section can be anonymous (type only, no name). Values are stored as strings; booleans are a convention (1/0/yes/no/on/off/true/false); UCI itself does not distinguish types.

Commands: stage first, then commit

uci show network                 # show the whole config
uci get network.wan.proto         # read a value
uci set network.wan.metric='20'   # change a value (staged)
uci add_list network.wan.dns='9.9.9.9'
uci delete network.wan.metric
uci changes                       # show staged changes
uci revert network                # discard uncommitted changes
uci commit network                # write /etc/config/network

Key behavior (official docs):

  • set/add/delete stage changes in /tmp/.uci;
  • before commit, uci get already returns the staged value;
  • commit writes the changes to the file;
  • commit does not make services reload.

So the full flow is:

uci set network.wan.metric='20'
uci commit network
reload_config
# or more precisely:
/etc/init.d/network reload

reload_config reloads the relevant services based on the last commit.

Anonymous sections and batching

Anonymous sections are addressed with @type[index]:

uci show firewall
# firewall.@zone[0].name='lan'
uci set firewall.@zone[0].input='ACCEPT'
uci add firewall rule

Note: deleting an earlier anonymous section shifts later indexes. Name sections when possible, especially in scripts.

Batch changes:

uci batch <<'EOF'
set network.wan.metric='20'
add_list network.wan.dns='9.9.9.9'
EOF
uci commit network

Reading from scripts

proto="$(uci -q get network.wan.proto)"
[ -n "$proto" ] || proto='dhcp'
  • -q is quiet, suitable for scripts;
  • do not assume a value exists; provide a default;
  • after writing, remember to commit, or it is lost on reboot.

Common pitfalls

  • Forgetting to commit: changes live only in /tmp/.uci and disappear on reboot;
  • Committing without reload: the file changed, but the service still uses the old config;
  • Expecting UCI to validate: UCI only stores values; type/range/dependencies are validated by the service, so an invalid value may commit successfully and fail on apply;
  • Treating boolean as a type: true/enabled/1 are conventions, not UCI syntax types;
  • Disabling a section by renaming it: the official docs mention this, but it is hard to read; use enabled when the service supports it;
  • Mixing list and option: add_list only makes sense for lists; set on an option overwrites it;
  • Concurrent writes: UCI is files + a staging area, not a database transaction; if two processes write, the later commit wins.

Boundaries: what it does not do

UCI solves “centralized, readable, scriptable configuration”; it does not solve:

  • a central schema / types / required fields / ranges;
  • cross-service atomic changes and rollback on failure;
  • object-level change events;
  • unified config + runtime state (OpenWrt also has ubus);
  • standard remote-management models such as TR-181/TR-369.

In one line: UCI is a configuration storage/editing layer, not a runtime data model. That is also why prplOS adds an Ambiorix/TR-181 layer on top of the OpenWrt base; see “From UCI to a data model: what prplOS improved, and why it is necessary”.

When UCI is enough

  • Home routers, single devices, a small number of services;
  • configuration is mainly read/edited by humans;
  • no need for cross-service transactions, object-level events, or a standard remote model.

Conversely, multi-WAN/multi-SSID, carrier CPE, TR-069/USP, and multi-vendor interop are where a data model starts to pay off.

Verification status

  • ✅ official docs: /etc/config, section/option/list, /tmp/.uci, commit, reload_config, anonymous sections;
  • ⚠️ not executed line by line on an OpenWrt device: commands are organized from the official docs; exact output depends on the target version;
  • ❓ version differences: details such as uci batch/rename should be checked with uci -h on the device.

One sentence

UCI turns configuration into “readable, editable, committable” text; it does not guarantee “apply succeeded”, and it does not own “runtime state”.


Sources: OpenWrt UCI usage · OpenWrt UCI technical reference Series: OpenWrt. Related: From UCI to a data model · UCI runtime/build dependencies.

Practice

Found this useful?

I write about AI agents × embedded / edge AI. Subscribe, or email me a concrete problem.

Guestbook →Subscribe (RSS)Support

Comments 0

No comments yet — be the first!

No login required; name is optional.