Hi there,
when setup a new network you might generate a bunch of static DHCP lease. But doing that using luci is a pain. I solved that using this script:
The script checks the uci-dhcp section if the MAC already exists. If not, the lease is added to the config.
As the dhcp-script option isn't included in the UCI-options, I had to add it into the dnsmasq.conf (as stated in the openwrt-wiki).
grep -q "dhcp-script" /etc/dnsmasq.conf || echo "dhcp-script=/etc/dnsmasq-remember.sh" >> /etc/dnsmasq.conf
cat > /etc/dnsmasq-remember.sh << 'EOF'
#!/bin/sh
mac=$2
ip=$3
hostname=$4
# Is the MAC already known?
if uci show dhcp | grep -q "${mac}"; then
logger -s "dhcp-remember.sh: MAC ${mac} already exists in config"
exit
fi
# in case you want only to record a specific IP range:
# if echo ${ip} | egrep -q -v '10\.0\.(19|23)\.'; then
# logger -s "dhcp-remember.sh: IP ${ip} ignored"
# exit
# fi
logger -s "dhcp-remember.sh: Adding static lease ${ip} for ${mac} ${hostname}"
uci add dhcp host
uci set dhcp.@host[-1].ip=${ip}
uci set dhcp.@host[-1].mac=${mac}
# If a hostname has been supplied we also set it:
[ -n "$hostname" ] && uci set dhcp.@host[-1].name="$hostname"
uci commit dhcp
EOF
chmod a+x /etc/dnsmasq-remember.sh
/etc/init.d/dnsmasq restart
Thanks to ruzickap, I used some hits in his code to solve this task!
(Last edited by joky on 10 Feb 2017, 08:05)