In modern network operations, the manual configuration of every new branch router is a bottleneck that invites human error and delays deployment. The industry standard for resolving this is “Zero-Touch Deployment,” where a device powers on in an unconfigured state and automatically downloads its initial operating system image and configuration file via DHCP Option 66 (TFTP Server Address) and Option 67 (Bootfile Name). This workshop guides you through building an Ansible-driven workflow to automate the provisioning of these DHCP services, ensuring that every new Cisco-style router in your lab or data center boots correctly without manual intervention.
Understanding the Zero-Touch Architecture
Before automating the process, it is crucial to understand the underlying protocol flow. When a network device boots with no configuration (factory default), it enters setup mode and attempts to obtain an IP address via DHCP. During this exchange, the DHCP server provides two critical pieces of information:
1. Option 66: The IP address of the TFTP server holding the boot files.
2. Option 67: The specific filename required to boot (e.g., bootflash:/c3850-k9-dvmx4-mz.152-4.M.bin).
Once the router obtains its IP and downloads the boot file, it proceeds to load the IOS image and eventually pull a full configuration file if defined in Option 150 or subsequent TFTP requests. Automation scripts must ensure that the DHCP scope is active, the TFTP server contains the correct files, and the Ansible playbook updates the router’s interface settings dynamically.
Prerequisites and Lab Environment Setup
To replicate a realistic workplace scenario without risking production stability, you should prepare a safe test environment. This section outlines the necessary components and version assumptions for this workshop.
Required Components:
* Operating System: Linux (Ubuntu 22.04 LTS or RHEL 9) acting as the DHCP/TFTP server.
* Network Devices: Two virtual routers (e.g., Cisco CSR1000V, GNS3 nodes, or EVE-NG images) connected to a switch and the DHCP server.
* Automation Engine: Ansible installed on the Linux host.
* Network Topology: A simple LAN where the router connects via its management port (Mgmt0/1) to the network segment containing the DHCP server.
File Preparation:
You must place a valid IOS image and a basic configuration file on the TFTP server. Create a directory structure like /srv/tftpboot/images and /srv/tftpboot/configs. Upload a sample binary (e.g., c3850-k9-dvmx4-mz.152-4.M.bin) and a text config (e.g., branch-router-startup.cfg). Ensure file permissions are set correctly (chmod 644) so the router can read them via TFTP.
Configuring the DHCP Server with Ansible
The core of the automation lies in updating the DHCP server configuration to serve the new branch routers. Using Ansible, we can apply changes consistently across multiple servers if needed. Below is a conceptual example using dnsmasq or isc-dhcp-server, commonly used in Linux environments.
# Example Ansible task to update dhcpd.conf or dnsmasq config
- name: Configure DHCP Option 66 and 67 for Branch Routers
hosts: dhcp_servers
become: yes
tasks:
- name: Include custom DHCP configuration snippet
copy:
dest: /etc/dhcp/dhcpd.conf
content: |
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.100 192.168.10.200;
option routers 192.168.10.1;
# Option 66: TFTP Server Address (encoded as domain name usually, but IP works)
host new-branch-router {
hardware ethernet xx:xx:xx:xx:xx:xx;
fixed-address 192.168.10.50;
filename "tftpboot/c3850-k9-dvmx4-mz.152-4.M.bin";
# Note: Option 66 is often passed via vendor-specific options or
# specific DHCP server implementations as option code 66.
next-server 192.168.10.1;
}
}
owner: root
group: root
mode: '0644'
- name: Restart DHCP service to apply changes
systemd:
name: isc-dhcp-server
state: restarted
Note: In isc-dhcp-server, Option 66 is typically handled via vendor-specific options or specific syntax depending on the version. For dnsmasq, you might use dhcp-boot=tag:vendor-class,file combined with dhcp-boot=tag:interface,subnet,host. Always verify the exact syntax against your distribution’s documentation.
Automating TFTP Server Readiness
The DHCP server alone is insufficient; the TFTP service must be running and accessible. Ansible can manage this state reliably.
- name: Ensure TFTP daemon is installed and started
hosts: dhcp_servers
become: yes
tasks:
- name: Install tftp-hpa package
apt:
name: tftp-hpa
state: present
update_cache: yes
- name: Start and enable TFTP service
systemd:
name: tftpd-hpa
enabled: yes
state: started
- name: Verify TFTP directory permissions
file:
path: /srv/tftpboot
state: directory
owner: root
group: root
mode: '0755'
This block ensures that even if a server reboot occurs, the TFTP service is ready to serve files immediately. It also sets the correct ownership for the TFTP root directory, which is a common security requirement to prevent unauthorized file uploads by the booting router.
Verifying the Zero-Touch Boot Process
Automation is only valuable if it works end-to-end. You must simulate the boot of a new router to validate the workflow. Connect an unconfigured router to your network and power it on. Observe the console output. The router should broadcast DHCP requests, receive an ACK containing Option 66 and 67, download the binary file via TFTP, and begin loading the image.
Expected Console Output (Illustrative):
%LINK-5-CHANGED: Interface GigabitEthernet0/0/0, changed state to up
DHCPD: Offering to client xx:xx:xx:xx:xx:xx on 192.168.10.1 port 67
TFTP: Loaded file c3850-k9-dvmx4-mz.152-4.M.bin (size: 45MB)
%SYS-5-CONFIG_I: Configured from flash:/c3850-k9-dvmx4-mz.152-4.M.bin:system
If the router halts at the prompt or fails to download the file, check the TFTP server logs (/var/log/syslog or journalctl -u tftpd-hpa) for permission errors or network reachability issues between the router’s management interface and the TFTP server.
Common Errors and Troubleshooting Strategies
Even in a controlled lab, several pitfalls can disrupt zero-touch bootstrapping. Here are frequent errors and how to resolve them using diagnostic commands.
- Firewall Blocking UDP Port 69: DHCP uses UDP ports 67/68, and TFTP uses UDP port 69. If your host firewall (iptables/nftables) or cloud security groups block these ports, the boot fails.
- Fix: Ensure
ufw allow 67andufw allow 69are active, or temporarily disable the firewall for testing in a lab.
- Fix: Ensure
- Filename Mismatch: The filename provided in Option 67 must match the exact file on the server, including path and extension. Case sensitivity matters on Linux.
- Fix: Use
ls -l /srv/tftpboot/to verify the exact string.
- Fix: Use
- Incorrect Subnet Mask or Gateway: If the router receives an IP but cannot reach the TFTP server, verify the routing table (
show ip route) and ensure the management VLAN is correctly routed to the DHCP server’s subnet.
Industry Application and Student Practice Task
For students and junior engineers, understanding this workflow is essential for roles in network automation engineering. In a real-world scenario, an ISP might deploy 50 new branch routers overnight using this method, eliminating the need for technicians to physically visit each site with laptops and keyboards.
Student Practice Task:
1. Set up a virtual lab using GNS3 or EVE-NG with one Linux host and two Cisco IOS images.
2. Configure the Linux host as both DHCP and TFTP server manually first.
3. Write an Ansible playbook that automates steps 1 through 4 above (installing packages, configuring /etc/dhcp/dhcpd.conf, starting services).
4. Run the playbook against your lab host.
5. Power on a third virtual router with no configuration and document whether it successfully boots into setup mode and downloads the image.
By mastering this automation pattern, practitioners can integrate Python or Bash scripts to generate unique configuration files for each branch site before pushing them via TFTP Option 67, creating a fully scalable, software-defined network provisioning pipeline.
Educational-use notice: This tutorial is for learning and controlled lab use only. Test carefully, use backups, and obtain authorization before making changes. Do not run unfamiliar commands on production systems. We accept no responsibility for misuse, damage, data loss, or production issues.

