Zero Touch Provisioning with dnsmasq on Debian 13: DHCP Options 66 and 67, TFTP Config Files per MAC Address

Zero touch provisioning sounds like a vendor feature, but the mechanism is two DHCP options and a file server. A switch or router powers up, gets an address by DHCP, is told where to fetch its configuration from, and fetches it. The server side can be a single dnsmasq process on a Debian box.

I built it in two network namespaces on my Debian 13 test VM: a server with dnsmasq, and a client that behaves like a device on first boot. The server hands out leases, announces a TFTP server and serves config files, with a different file for one specific MAC address.

The two options

OptionNameCarries
66TFTP server namethe address or name of the server to fetch from
67Bootfile namethe file name to request

dnsmasq also fills the “next server” field in the DHCP header, which older devices use instead of option 66.

Install

sudo apt install dnsmasq tftp-hpa
dnsmasq 2.91-1+deb13u2
tftp-hpa 5.2+20240610-3

tftp-hpa is only the test client. The server is built into dnsmasq. Installing dnsmasq starts a system service on Debian. In my case it was inactive and disabled, but check yours before running a second instance, because two DHCP servers on one segment is a classic way to break a lab.

The server configuration

port=0
interface=z0
bind-interfaces
dhcp-range=10.20.0.50,10.20.0.99,255.255.255.0,2m
dhcp-option=3,10.20.0.1
dhcp-option=66,10.20.0.1
dhcp-boot=default.cfg

# per-device config: this MAC gets its own file and a fixed address
dhcp-host=02:00:00:00:0a:01,set:sw1,10.20.0.60
dhcp-boot=tag:sw1,sw-edge-01.cfg

enable-tftp
tftp-root=/tmp/z/tftp
log-dhcp
log-facility=/tmp/z/dnsmasq.log

What it does:

  • port=0 turns off dnsmasq’s DNS function, so it only does DHCP and TFTP. Without it, dnsmasq also tries to bind port 53.
  • interface= with bind-interfaces limits where it listens. A DHCP server answering on the wrong interface is the other way to break things.
  • dhcp-boot=default.cfg sets option 67 for everyone.
  • dhcp-host=<mac>,set:sw1,... gives that MAC a fixed address and a tag. The dhcp-boot=tag:sw1,... line then overrides the file name for anything with that tag. Order matters in the sense that the tagged line is more specific, and it won.
  • enable-tftp and tftp-root serve files from one directory.
  • log-dhcp is what makes this debuggable. Leave it on while you build.

Always check the syntax first:

$ dnsmasq --test --conf-file=/tmp/z/dnsmasq.conf
dnsmasq: syntax check OK.

The sockets after start:

0.0.0.0%z0:67
10.20.0.1:69

It listens for DHCP on the one interface and TFTP on the interface address, plus loopback and the IPv6 equivalents.

The files

Two plain text configs in the TFTP root:

default.cfg       generic bootstrap for any unknown device (140 bytes)
sw-edge-01.cfg    the config for the one known switch

and the second one reads:

hostname sw-edge-01
banner motd Provisioned via ZTP
ntp server 10.20.0.1

Make the files world-readable. dnsmasq serves them as an unprivileged user, so a chmod 600 file owned by root is not served. I tested that deliberately, and the client got Error code 2: cannot access /tmp/z/tftp/sw-edge-01.cfg: Permission denied.

The client

My “device” is dhcpcd in test mode, asked for the same two options a real device would:

option tftp_server_name
option bootfile_name
clientid
sudo ip netns exec zc dhcpcd -T -f /tmp/z/dhcpcd.conf z1

Test mode (-T) does the negotiation and prints the result without configuring the interface.

Case 1: an unknown device

A client with a random MAC address received:

z1: soliciting a DHCP lease
z1: offered 10.20.0.70 from 10.20.0.1

and the server log recorded the decision:

DHCPDISCOVER(z0) 1a:8c:bd:a1:3a:fa
tags: z0
DHCPOFFER(z0) 10.20.0.70 1a:8c:bd:a1:3a:fa
requested options: ... 66:tftp-server, 67:bootfile-name
next server: 10.20.0.1
sent size: 12 option: 67 bootfile-name  default.cfg
sent size: 10 option: 66 tftp-server  10.20.0.1

The log shows both halves of the conversation: the options the client asked for (requested options) and the options the server sent. When a device does not provision, this log is the first place to look. If 66 or 67 are missing from requested options, the device is not asking, and no server configuration will help.

Case 2: the known MAC

I changed the client’s MAC to 02:00:00:00:0a:01 and repeated the request. The log says:

DHCPDISCOVER(z0) 02:00:00:00:0a:01
tags: sw1, known, z0
DHCPOFFER(z0) 10.20.0.60 02:00:00:00:0a:01

The tags now include sw1 and known. dhcpcd’s test output reports what the client would apply:

new_ip_address='10.20.0.60'
new_routers='10.20.0.1'
new_tftp_server_name='10.20.0.1'
new_bootfile_name='sw-edge-01.cfg'

Same server, different device, different file.

The fetch

A device in test mode does not take up the lease, so I added the address by hand and fetched like a device would:

$ tftp -4 10.20.0.1 -c get sw-edge-01.cfg
hostname sw-edge-01
banner motd Provisioned via ZTP
ntp server 10.20.0.1

The server logged what it did:

dnsmasq-tftp: sent /tmp/z/tftp/sw-edge-01.cfg to 10.20.0.60
dnsmasq-tftp: sent /tmp/z/tftp/default.cfg to 10.20.0.60
dnsmasq-tftp: file /tmp/z/tftp/nope.cfg not found for 10.20.0.60

I used -4 because the tftp client tried IPv6 first and complained “Address family for hostname not supported”. And the client needs an IPv4 address on the interface before it will talk, otherwise it reports unknown host even for a literal IP. That cost me a few minutes.

On the wire

Capturing on the server interface shows the request in clear text:

10.20.0.60.36715 > 10.20.0.1.69: TFTP, length 26, RRQ "sw-edge-01.cfg" netascii
10.20.0.60.47946 > 10.20.0.1.69: TFTP, length 23, RRQ "default.cfg" netascii
10.20.0.60.38792 > 10.20.0.1.69: TFTP, length 20, RRQ "nope.cfg" netascii

And the DHCP offer:

TFTP (66), length 10: "10.20.0.1^@"

The value is 10 bytes, not 9. The extra byte is a trailing NUL after the address string, which dnsmasq includes. Some devices are fussy about that. If a particular switch ignores option 66, check what it does with the terminator, or use the “next server” field, which is a plain address.

Two consequences of the protocol are worth stating:

  • TFTP has no authentication or encryption. Anyone who can reach the server can read the files, so never put credentials in a ZTP config. Have the bootstrap config fetch secrets over HTTPS or SSH after the device has an identity.
  • Anyone on the segment can answer DHCP. ZTP is for a provisioning VLAN you control, with DHCP snooping on the rest.

I also asked for ../dnsmasq.conf to see whether the server would leave the TFTP root. It refused (Permission denied), but since the unreadable file test gave the same message, I would not rely on that as a security control. dnsmasq has a tftp-secure option for locking down access, and I did not test it.

Where this stops

This was tested with a Linux DHCP client, so it shows the server side only. Real devices have their own conventions: some look for a file named after their serial number, MAC or model, some use option 43 or option 150, and some want a Python or YAML bootstrap file rather than a config. The mechanism is the same, and the dnsmasq tags (set: and tag:) are how you express those rules, but check each vendor’s documentation and test with the real hardware.

A reusable pattern

  1. Put a default bootstrap file in the TFTP root, so unknown devices get something safe.
  2. Add one dhcp-host= and dhcp-boot=tag: pair per device you want to configure individually.
  3. Keep log-dhcp on and read the log when something fails.
  4. Run it on an isolated VLAN.

That is a complete zero touch provisioning setup in about fifteen lines of configuration, and every step is visible in a log you can read.