dnsmasq (2/2)
The second half of dnsmasq: DNSSEC validation, authoritative zones, the full DHCP server (ranges, static hosts, options, tags, relay, PXE, leases, scripts), IPv6 router advertisement, TFTP and runtime signals. One config gives a small network DNS, DHCP and network boot together.
93.1 What the DHCP side does
| Job | Port / protocol | Key option |
|---|---|---|
| DNS | UDP/TCP 53 | server=, --dnssec, --auth-zone |
| DHCP | UDP 67 | --dhcp-range, --dhcp-host, --dhcp-option |
| TFTP | UDP 69 | --enable-tftp, --tftp-root |
| IPv6 RA | ICMPv6 type 134 | --enable-ra, --ra-param |
- Linux: apt/dnf/apk install dnsmasq (Alpine needs dnsmasq-dnssec for DNSSEC).
- macOS: brew install dnsmasq; Windows: not native, use WSL or a Linux VM.
- Lab: dnsmasq 2.90 server at 192.168.113.10 on n093-lan; clients test with dhcp-test (a udhcpc wrapper).
93.2 How DHCP works: DORA and relay
- Step 1
1.Laptop (no IP yet) broadcasts DHCP DISCOVER
- Step 2
2.Docker bridge n093-lan carries it to every device
- Step 3
3.dnsmasq 192.168.113.10 picks a free IP and sends OFFER .104
- Step 4
4.Laptop sends REQUEST for .104
- Step 5
5.dnsmasq replies ACK: 192.168.113.104, router, DNS, lease 12h
- Step 1
1.Far LAN PC (192.168.113.128/25) broadcasts DISCOVER
- Step 2
2.dnsmasq relay (.130 / .5) receives it
- Step 3
3.Relay forwards it as unicast to the server 192.168.113.10
- Step 4
4.Server picks the range matching relay address .130
- Step 5
5.OFFER .216 comes back through the relay; router = .130
93.3 DNSSEC
# Alpine ki file: sirf root KSK 20326dnsmasq -d -C /etc/n093/base.conf -q \ --dnssec --conf-file=\/usr/share/dnsmasq/trust-anchors.confdig +dnssec example.com# anchors.conf: KSK 20326 + KSK 38696dnsmasq -d -C /etc/n093/base.conf -q \ --dnssec \ --conf-file=/etc/n093/anchors.conf \ --dnssec-check-unsigneddig +dnssec example.comdig +dnssec dnssec-failed.org$ dig +dnssec example.com;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 50246;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1dnsmasq: configured with trust anchor for <root> keytag 20326dnsmasq: reply . is BOGUS DNSKEYdnsmasq: validation example.com is BOGUS$ dig +dnssec example.com;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3586;; flags: qr rd ra ad; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1dnsmasq: reply . is DNSKEY keytag 38696, algo 8dnsmasq: validation result is SECURE$ dig +dnssec dnssec-failed.org;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 14573;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1dnsmasq: validation dnssec-failed.org is BOGUSdnsmasq: reply error is SERVFAIL- --dnssec checks the signature chain of every answer up to the root and sets the AD bit when it is SECURE.
- Alpine's anchors file had only the old root KSK 20326; the root key set is now signed by KSK 38696, so even example.com was BOGUS (SERVFAIL).
- With both anchors: example.com gets the ad flag; the deliberately broken dnssec-failed.org still gets SERVFAIL.
- --proxy-dnssec does not validate, it passes on the upstream AD flag; --dnssec-debug sets CD and never returns SERVFAIL.
- --dnssec-no-timecheck / --dnssec-timestamp help devices with no RTC (signatures are time-bound).
93.4 Authoritative DNS server
dnsmasq -d -C /etc/n093/base.conf -q \ --auth-server=ns.lab.example,eth0 \ --auth-zone=lab.example,192.168.113.0/25 \ --auth-soa=2026110901,\hostmaster.lab.example \ --auth-peer=192.168.113.20 \ --host-record=www.lab.example,\192.168.113.80dig @192.168.113.10 www.lab.exampledig @192.168.113.10 lab.example AXFR# printer 192.168.113.21 sedig @192.168.113.10 lab.example AXFR$ dig @192.168.113.10 www.lab.example;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1www.lab.example. 600 IN A 192.168.113.80lab.example. 600 IN NS ns.lab.example.$ dig @192.168.113.10 lab.example AXFRlab.example. 600 IN SOA ns.lab.example. hostmaster.lab.example. 2026110901 1200 180 1209600 600lab.example. 600 IN NS ns.lab.example.www.lab.example. 600 IN A 192.168.113.80lab.example. 600 IN SOA ns.lab.example. hostmaster.lab.example. 2026110901 1200 180 1209600 600$ dig @192.168.113.10 lab.example AXFR; Transfer failed.dnsmasq: auth[AXFR] lab.example from 192.168.113.21dnsmasq: ignoring zone transfer request from 192.168.113.21dnsmasq: config error is REFUSED- The aa flag means an authoritative answer.
- AXFR (zone transfer) is allowed only to --auth-peer 192.168.113.20; the printer .21 was REFUSED.
- --auth-server=NAME,IF/4 or /6 limits the family; --auth-sec-servers names secondaries.
93.5 DHCP ranges and static hosts
dnsmasq -d -C /etc/n093/base.conf \ --dhcp-range=192.168.113.100,\192.168.113.120,12h \ --dhcp-host=02:93:00:00:00:21,printer,\192.168.113.50,infinite \ --dhcp-hostsfile=/etc/n093/dhcp-hosts \ --dhcp-host=02:93:00:00:00:23,ignoredhcp-test # printer, MAC ..:21dhcp-test # laptop, MAC ..:20dhcp-test # PXE box, MAC ..:23$ dhcp-testudhcpc: lease of 192.168.113.50 obtained from 192.168.113.10, lease time 4294967295bound: ip=192.168.113.50 mask=255.255.255.128 lease=4294967295 hostname=printer$ cat /etc/n093/dhcp-hosts02:93:00:00:00:20,laptop,192.168.113.60$ dhcp-testbound: ip=192.168.113.60 mask=255.255.255.128 lease=43200 hostname=laptop$ dhcp-testudhcpc: no lease, failingdnsmasq-dhcp: DHCPDISCOVER(eth0) 02:93:00:00:00:23 ignored| --dhcp-range form | Meaning |
|---|---|
| START,END,12h | IPv4 pool + lease time (laptop got 192.168.113.104, lease 43200) |
| ...,infinite | Lease never expires (lease time 4294967295) |
| START,static | No pool: only dhcp-host entries (unknown laptop: no address available) |
| ...,MASK | Range for a relayed network that is not directly connected |
| START,proxy | Proxy-DHCP (PXE only, another server gives IPs) |
| ::,constructor:IF,ra-stateless | IPv6 from the interface prefix (see RA) |
93.6 DHCP options and tags
dnsmasq -d -C /etc/n093/base.conf \ --dhcp-range=192.168.113.100,\192.168.113.120,12h \ --dhcp-option=option:router,192.168.113.1 \ --dhcp-option=option:dns-server,\0.0.0.0,1.1.1.1 \ --dhcp-option=option:ntp-server,\192.168.113.10 \ --dhcp-option=26,1400 \ --dhcp-option=121,172.16.0.0/12,\192.168.113.1dhcp-test -O mtu -O staticroutes$ dhcp-test -O mtu -O staticroutesbound: ip=192.168.113.104 mask=255.255.255.128 lease=43200 router=192.168.113.1 dns=192.168.113.10 1.1.1.1 ntpsrv=192.168.113.10 mtu=1400 staticroutes=172.16.0.0/12 192.168.113.1- dns-server 0.0.0.0 means 'the dnsmasq machine itself' (sent as 192.168.113.10).
- Option 26 = MTU, 121 = classless static route; names come from dnsmasq --help dhcp (3 router, 6 dns-server...).
- Tags decide who gets what: dhcp-host ...,set:printer + dhcp-option=tag:printer,... gave only the printer an NTP server.
- --dhcp-vendorclass=set:pxe,PXEClient tags PXE boxes; --dhcp-ignore=tag:!known,tag:!pxe ignored the unknown laptop.
- --dhcp-option-force sends an option even if the client did not ask.
93.7 DHCP relay
# srv: far LAN ke liye second rangednsmasq -d -C /etc/n093/base.conf \ --dhcp-range=192.168.113.100,\192.168.113.120,12h \ --dhcp-range=192.168.113.200,\192.168.113.220,255.255.255.128,1h# relay: 192.168.113.130 + .5dnsmasq -d --port=0 \ --dhcp-relay=192.168.113.130,192.168.113.10dhcp-test # far PC, MAC ..:41$ dnsmasq -d --port=0 --dhcp-relay=192.168.113.130,192.168.113.10dnsmasq: started, version 2.90 DNS disableddnsmasq-dhcp: DHCP relay from 192.168.113.130 to 192.168.113.10$ dhcp-testudhcpc: lease of 192.168.113.216 obtained from 192.168.113.10, lease time 3600bound: ip=192.168.113.216 mask=255.255.255.128 lease=3600 router=192.168.113.130 dns=192.168.113.1093.8 PXE boot and TFTP
dnsmasq -d -C /etc/n093/base.conf \ --dhcp-range=192.168.113.100,\192.168.113.120,12h \ --dhcp-vendorclass=set:pxe,PXEClient \ --dhcp-boot=tag:pxe,pxelinux.0 \ --enable-tftp --tftp-root=/srv/tftp \ --tftp-secure --tftp-max=20dhcp-test -V PXEClient # PXE boxcurl -s tftp://192.168.113.10/pxelinux.0curl -sS tftp://192.168.113.10/grubx64.eficurl -sS \ tftp://192.168.113.10/../etc/passwd$ dhcp-test -V PXEClientbound: ip=192.168.113.107 mask=255.255.255.128 lease=43200 router=192.168.113.10 boot_file=pxelinux.0 siaddr=192.168.113.10$ curl -s tftp://192.168.113.10/pxelinux.0hello from n093 tftp (fake boot file)dnsmasq-tftp: TFTP root is /srv/tftp secure modednsmasq-tftp: sent /srv/tftp/pxelinux.0 to 192.168.113.23$ curl -sS tftp://192.168.113.10/grubx64.eficurl: (68) TFTP: File Not Found$ curl -sS tftp://192.168.113.10/../etc/passwdcurl: (68) TFTP: File Not Founddnsmasq-tftp: file /srv/tftp/etc/passwd not found for 192.168.113.23- A diskless machine boots from the network: DHCP gives boot_file + siaddr (TFTP server), then it downloads the file over TFTP.
- --tftp-secure serves only from inside the root: ../etc/passwd was looked up as /srv/tftp/etc/passwd.
- --pxe-service / --pxe-prompt build a PXE menu; --tftp-unique-root gives each client its own folder; --tftp-single-port helps NAT.
93.9 Leases, lease scripts and DNS integration
$ cat /var/lib/n093/dnsmasq.leases1794224621 02:93:00:00:00:21 192.168.113.101 * 01:02:93:00:00:00:211794224615 02:93:00:00:00:20 192.168.113.100 * 01:02:93:00:00:00:20$ cat /etc/n093/lease.sh#!/bin/sh# dnsmasq calls: <action> <mac> <ip> [hostname]echo "$1 $2 $3 ${4:-} tags=${DNSMASQ_TAGS:-}" >> /tmp/lease-events.log$ cat /tmp/lease-events.logadd 02:93:00:00:00:20 192.168.113.104 laptop tags=eth0$ dig +short laptop.lab192.168.113.104$ dig +noall +comments ghost.lab;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 14324- --dhcp-sequential-ip gave .100 then .101 (in order, not by hash); --dhcp-lease-max=2 made the third client get NAK after every offer.
- Lease file line: expiry time, MAC, IP, hostname, client-id.
- --dhcp-authoritative: the only DHCP server on the net, answers unknown leases at once; --dhcp-rapid-commit, --no-ping also here.
- --dhcp-script runs on add / old / del with args ACTION MAC IP [HOSTNAME] and env like DNSMASQ_TAGS.
- --domain=lab,192.168.113.0/25,local: a client sending hostname laptop gets A + PTR for laptop.lab at once; unknown ghost.lab gets NXDOMAIN, never forwarded.
93.10 IPv6 router advertisement
dnsmasq -d --port=0 --enable-ra \ --dhcp-range=::,constructor:eth0,\ra-stateless \ --ra-param=eth0,high,10# pc par RA capturetimeout 25 tcpdump -i eth0 -n -c 1 -vv \ 'icmp6 and ip6[40] == 134'23:45:05.506446 IP6 (class 0xc0, flowlabel 0x88dad, hlim 255, next-header ICMPv6 (58) payload length: 64) fe80::93:ff:fe00:10 > ff02::1: [icmp6 sum ok] ICMP6, router advertisement, length 64 hop limit 64, Flags [other stateful], pref high, router lifetime 30s, reachable time 0ms, retrans timer 0ms prefix info option (3), length 32 (4): fd00:113::/64, Flags [onlink, auto], valid time infinity, pref. time infinity mtu option (5), length 8 (1): 1500 source link-address option (1), length 8 (1): 02:93:00:00:00:10- The RA is built from the interface prefix fd00:113::/64 with flags onlink + auto (SLAAC).
- --ra-param=eth0,high,10: high priority, 10 s interval, so router lifetime came out 30 s.
- Router lifetime 0 = prefix given but no default route; mtu:1280 / mtu:off control the MTU option.
93.11 Signals and runtime control
| Signal | What dnsmasq does |
|---|---|
| SIGHUP | Clears cache, re-reads hosts, ethers, hostsfile (NOT dnsmasq.conf) |
| SIGUSR1 | Writes cache and upstream stats to the log |
| SIGUSR2 | Reopens the log file (log rotation) |
| SIGINT | Turns DNSSEC time checks on after --dnssec-no-timecheck |
$ dhcp-testbound: ip=192.168.113.60 mask=255.255.255.128 lease=43200$ pkill -HUP dnsmasqdnsmasq-dhcp: read /etc/n093/dhcp-hosts$ dhcp-testbound: ip=192.168.113.70 mask=255.255.255.128 lease=43200$ pkill -USR1 dnsmasqdnsmasq: cache size 150, 0/2 cache insertions re-used unexpired cache entries.dnsmasq: queries forwarded 1, queries answered locally 1dnsmasq: server 8.8.8.8#53: queries sent 1, retried 0, failed 0, nxdomain replies 0, avg. latency 37ms93.12 Common mistakes
- Every domain SERVFAIL right after enabling DNSSEC: check trust anchors (root KSK 38696 needed) and the clock.
- Expecting SIGHUP to reload dnsmasq.conf: it only reloads hosts/hostsfile; run dnsmasq --test, then restart.
- Expecting DHCP broadcasts to cross a router: use a relay (--dhcp-relay) and a MASK range on the server.
- PXE without TFTP: dhcp-boot alone is not enough.
93.13 Interview tips
- DHCP = DORA: Discover, Offer, Request, Ack (UDP 67/68); a relay turns the broadcast into unicast to a remote server.
- dnsmasq suits small LANs, labs, routers and PXE (DNS + DHCP + TFTP in one process); large networks use Kea DHCP + BIND/Unbound for failover and APIs.
- PXE = dhcp-boot (boot file + siaddr) + TFTP server.
- DNSSEC needs correct trust anchors and a correct clock; AD flag = validated.
- SIGHUP is not a full reload.