OpenWrt-based DHCP/DNS server

This document describes how to build a simple DHCP/DNS server on top of OpenWrt. We assume you already have a working OpenWrt installation and that you have configured basic networking (/etc/config/network) and the host’s name (/etc/config/system).

The following will configure dnsmasq to provide DHCP (assigning .1–.100), and DNS (e.g., assigning the hostname to the computer with MAC address aa:bb:cc:dd:ee:ff). The DNS service will also resolve the local host’s name, as set in /etc/config/system.

config dnsmasq
        option domainneeded '1' 
        option boguspriv '1'
        option filterwin2k '0'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/'
        option domain ''
        option expandhosts '1'
        option nonegcache '0'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/'
        option server '' # Upstream DNS.

config dhcp 'lan'
        option interface 'lan'
        option start '1'
        option limit '100'
        option leasetime '12h'
        option dhcpv6 'server'
        option ra 'server'
        list dhcp_option '3,' # Default gateway.
        list dhcp_option '121,,' # A static route.

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'

config host
        option name ''
        option ip ''
        option mac 'aa:bb:cc:dd:ee:ff'