Key takeaways
- Zero-touch provisioning (ZTP) is a chain: factory image, unique device identity, first-boot bootstrap, phone-home, claim, template assignment.
- Every device needs its own credential, ideally a per-device key and certificate. Shared default passwords defeat the point.
- Separate "device is genuine" (identity) from "device belongs to this customer" (claim); never trust the network the device is plugged into.
- Design for failure: no WAN, wrong time, unreachable controller and returned units are normal cases, not edge cases.
Zero-touch provisioning means a router leaves the warehouse in a generic state, someone at the site plugs in power and WAN, and within minutes it is running the right configuration for that customer, without an engineer on site or a laptop on the LAN port. On OpenWrt, all the pieces exist. The engineering work is in joining them securely and handling the cases where things go wrong.
The end-to-end ZTP flow
A robust ZTP design has six stages. Each one must be able to fail safely and retry.
The factory image and bootstrap agent
Start with a single generic image per hardware model, built with the OpenWrt SDK or Image Builder. It contains three things beyond stock OpenWrt:
- A bootstrap agent, run as a procd service, whose only job before claiming is to reach the controller and fetch instructions.
- The controller's CA certificate and the provisioning endpoint name, so the device can verify it is talking to your service and not an impostor.
- Safe defaults: WAN as a DHCP client, firewall input rejected on WAN, SSH limited to keys or disabled, LuCI optionally removed or bound to LAN only.
Avoid customer-specific content in this image. The moment the image differs per customer, the warehouse has to know which box goes where, and ZTP becomes "some-touch provisioning".
Device identity: serial, MAC and per-device keys
The controller must be able to tell genuine devices apart and recognise each one individually. A serial number or MAC address is an identifier, not a credential: both are printed on the box and easy to copy. Identity needs a secret only that device holds.
Two common approaches:
| Approach | How it works | Trade-offs |
|---|---|---|
| Factory-injected certificate | A key pair and certificate signed by your manufacturing CA are written to a dedicated partition during production test | Strongest; needs a secure factory process and a partition that survives sysupgrade and factory reset |
| Key generated on first boot | Device generates a key, sends a signing request with its serial; controller approves against a manufacturing manifest | No secrets in the factory; relies on the manifest and first-connection trust |
Store factory-injected credentials outside the overlay filesystem. A factory reset wipes the overlay; if the device's identity lives there, a customer pressing the reset button turns it into an unknown device. Where the SoC supports secure storage, use it.
Warning: Never ship a shared default password or a shared API key in the image. Stock OpenWrt has no root password on first boot; production builds must disable password login or set a unique per-device password printed on the label.
First boot with uci-defaults
Scripts in /etc/uci-defaults/ run once on first boot and are deleted when they exit 0. Use them to derive per-device values from hardware rather than from the image:
#!/bin/sh
# files/etc/uci-defaults/95-ztp-identity
MAC=$(cat /sys/class/net/eth0/address | tr -d ':') # interface name varies by board
SUFFIX=$(echo "$MAC" | tail -c 7)
uci -q batch <<EOF
set system.@system[0].hostname='cw-$SUFFIX'
set network.wan.vendorid='ExampleCo-ZTP'
commit
EOF
# The agent reads identity from the factory partition at runtime
/etc/init.d/ztp-agent enable
exit 0
Setting vendorid on the WAN interface makes the DHCP client send option 60 (vendor class identifier), which a cooperating ISP or enterprise DHCP server can use to recognise your devices.
Finding the controller: DNS and DHCP options
The simplest discovery is a fixed DNS name compiled into the image. It works on any network with working DNS and is easy to reason about. Where you control or cooperate with the local network, DHCP can override it:
- Option 60 identifies the device class to the DHCP server.
- Option 43 (vendor-specific information) can return a controller URL. Request it with the
reqoptsoption on the interface and handle it in a udhcpc hook such as/etc/udhcpc.user. - Option 138 or a custom option is used by some vendors for controller discovery.
Treat any controller address learned from the local network as a hint, not as trust. The device must still verify the controller's certificate against the CA in the image. Otherwise anyone running a DHCP server on the customer's LAN can redirect your devices.
Phone home and the claim flow
On reaching the controller, the device authenticates with its per-device credential over mutual TLS and presents its serial, MAC, model and firmware version. The controller now knows the device is genuine. It does not yet know who owns it.
Ownership is established by claiming, which is a separate, human-authorised step. Common patterns are: the reseller uploads a list of serials against a customer order; the installer scans a QR code on the label in a mobile app; or the customer enters the serial and a claim code printed inside the box. Unclaimed devices should sit in a quarantine state with only provisioning access.
Assigning templates
Once claimed, the device is placed into a tenant, site and group, and the matching configuration template is rendered with its variables: SSIDs, VLANs, WAN settings, VPN keys. The agent applies the configuration with a safe-apply pattern: apply, confirm the controller is still reachable, otherwise revert. If the template requires a newer firmware build, upgrade first, then apply configuration. Our configuration management guide covers template design in detail.
Failure handling
Most ZTP problems at sites are mundane. Design the agent and support process around them:
- No WAN or captive upstream: retry with backoff; show state on an LED pattern or a LAN-side status page so an installer can tell "no internet" from "no controller".
- Wrong clock: TLS fails if the clock is wrong: OpenWrt boots with roughly the image build time, so certificates issued after the build look "not yet valid". Sync time over NTP before connecting, and tolerate certificate validity windows sensibly during bootstrap.
- Controller unreachable: exponential backoff with jitter, so a backend outage does not end with every device reconnecting at once.
- Configuration rejected: keep the last working configuration and report the error rather than leaving the device half-configured.
- Unknown device: a serial not in any manifest should alert, not be auto-accepted.
RMA and re-provisioning
Returned and replacement devices are where ZTP designs often break. Plan the lifecycle explicitly:
- Replacement: let support move a site's configuration from the failed device to a new serial, so the replacement provisions itself into the same role.
- Return: un-claim the device, revoke or retain its certificate according to policy, and wipe customer configuration before refurbishment.
- Factory reset in the field: because identity survives in its own partition, a reset device simply phones home again and is re-provisioned into its existing assignment.
- Resale: a device claimed by one tenant must be released before another can claim it.
TIP OpenWiFi and uCentral as one approach
The Telecom Infra Project's OpenWiFi stack is an open reference for exactly this problem on Wi-Fi access points and switches. Devices run the OpenWrt-based OpenWiFi firmware with the uCentral client, carry a device certificate, discover their controller and keep a persistent connection to the uCentral gateway, which pushes JSON configuration and collects telemetry. It is a good fit when you want multi-vendor hardware and an established open controller rather than designing your own protocol, and the trade-off is adopting its device certificate process and operating its controller services.
How CloudWRT helps
Our OpenWiFi services are based on TIP OpenWiFi with uCentral, zero-touch provisioning and multi-tenancy. For general OpenWrt fleets, the CloudWRT Platform provides device grouping, configuration templates with variable substitution and scheduled rollouts with rollback once devices are enrolled.
If you are an OEM designing ZTP into a new product, our R&D team can build the factory image, bootstrap agent, identity partition and first-boot logic as part of a custom OpenWrt build. You can also start a free trial to test the platform with your hardware.
Frequently asked questions
Can zero-touch provisioning work behind NAT?
Yes. The device makes an outbound TLS connection to the controller, so it works behind NAT and CGNAT without any inbound ports.
Is the MAC address enough to identify a device?
It is fine as an identifier but not as a credential, because it is easy to read and copy. Pair it with a per-device key and certificate so the controller can verify the device is genuine.
What happens if a customer factory-resets a provisioned router?
If the device identity is stored outside the overlay filesystem, the device phones home again after reset and is re-provisioned with its existing assignment.
Do I need DHCP option 43 for ZTP?
No. A fixed DNS name in the image is simpler and works almost everywhere. DHCP options are useful when you control the local network and want to override the default controller.