-
Notifications
You must be signed in to change notification settings - Fork 17
dnsmasq fails to start due to duplicate dhcp-host entries silently allowed in UCI /etc/config/dhcp #17
Description
When multiple host sections in /etc/config/dhcp assign the same static IP address (e.g., option ip '192.168.0.48') — even for different MAC addresses — no validation is performed during uci commit or service reload.
As a result, the generated dnsmasq config (/var/etc/dnsmasq.conf.*) contains duplicate dhcp-host entries, and dnsmasq refuses to start with:
daemon.crit dnsmasq[1]: duplicate dhcp-host IP address 192.168.0.48 at line XX of /var/etc/dnsmasq.conf.cfgXXXXXX
daemon.crit dnsmasq[1]: FAILED to start up
This causes:
No DHCP service → clients have no gateway or DNS
No DNS resolution
odhcpd logs "No default route present, setting ra_lifetime to 0!" due to missing WAN route (indirect effect)
Router becomes practically unusable for LAN clients
Expected behavior
The system should prevent or warn about duplicate static IP assignments before writing the dnsmasq config, ideally at one of these layers:
In LuCI (web UI): validation on form submit
In UCI CLI: uci add dhcp host or uci set should reject duplicates
In /etc/init.d/dnsmasq: check or reload should validate uniqueness of option ip across all dhcp host sections
At minimum: log a clear warning during config generation
Note: dnsmasq itself behaves correctly — it must not allow duplicate static leases. The bug is in OpenWrt’s config generation/validation layer, not in upstream dnsmasq.
How to reproduce:
- Add two static DHCP leases with the same IP:
uci add dhcp host
uci set dhcp.@host[-1].name='device1'
uci set dhcp.@host[-1].ip='192.168.0.48'
uci set dhcp.@host[-1].mac='aa:bb:cc:dd:ee:ff'
uci add dhcp host
uci set dhcp.@host[-1].name='device2'
uci set dhcp.@host[-1].ip='192.168.0.48'
uci set dhcp.@host[-1].mac='11:22:33:44:55:66'
uci commit dhcp
-
Restart dnsmasq:
/etc/init.d/dnsmasq restart -
Observe crash loop:
logread | grep -i "duplicate.*dhcp-host"
Environment
OpenWrt Version: 23.05.3 (or any recent version)
Architecture: aarch64 (e.g., AX3000T)
Packages: dnsmasq, odhcpd, luci
dnsmasq version: 2.90
Suggested fix
Add validation in /etc/init.d/dnsmasq (or in a shared UCI validation hook) that:
Parses all config host sections in /etc/config/dhcp
Checks for duplicate option ip values
Fails gracefully with a clear error if duplicates are found
Example validation (bash):
check_duplicate_static_ips() {
awk -F"'" '
/^config host/ { in_host=1; ip="" }
in_host && /option ip / { ip=$2; if (seen[ip]) { print "ERROR: duplicate static IP " ip; exit 1 } seen[ip]=1 }
/^[[:space:]]*$/ || /^[^[:space:]]/ { in_host=0 }
' /etc/config/dhcp
}
Call this in the check or reload action of /etc/init.d/dnsmasq.