Site Tools


retain_dhcp_lease_info_after_a_reboot

This is an old revision of the document!


Retain DHCP Lease Information after a Reboot

By default, dnsmasq stores DHCP lease information in RAM. This means that operations such as a reboot will erase the lease database, forcing a new one to be created. This could be inconvenient, since devices might receive a new IP address after DHCP renewal. For dnsmasq to maintain its DHCP lease information, persistent storage, (such as USB) is needed. There are currently two options you might consider:

1) This isn't a scripting method/example per se. It may not be what you're looking for.

Navigate to DHCP/DNS under the Advanced menu. In the Dnsmasq Custom configuration field, enter:

dhcp-leasefile=/mnt/usb/dnsmasq/dnsmasq.leases

Use a path relative to your own system. Click Save.

The idea is essentially to store the lease database directly on non-volatile storage. This can be useful, for example, when devices are connected to a switch. They won't lose network connectivity if the router is down (rebooted). They won't display as having an active lease in the Device List until their current lease expires, and they request a new one. FreshTomato will just continue where if left off. Please also notice the example above points to a USB device with a label name “usb” you might have different names on your system depending on how the storage was formatted. This also means you can store on different permanent storage e.g. CIFS. For this specific operation though you are discouraged from using JFFS as this latter is never recommended for frequent writes (as it would occur every time a new IP is dispatched).


2) A different approach is to keep the lease database in its default location and copy it to permanent storage at “halt” time to then restore it when the device runs the “init” at boot. e.g.

Administration/Scripts/Init

[ -f /mnt/usb/dnsmasq.leases ] && {
 sort -b -k 2 -u -z /tmp/var/lib/misc/dnsmasq.leases > /tmp/dnsmasq.tmp1
 sort -b -k 2 -u -z /mnt/usb/dnsmasq.leases > /tmp/dnsmasq.tmp2
 diff -a /tm
 kill -HUP `ps | grep 
 rm /tmp/dnsmasq.tmp1
 rm /tmp/dnsmasq.tmp2
}

Administration/Scripts/Halt

cp -f /tmp/var/lib/misc/dnsmasq.leases /mnt/usb/dnsmasq.leases

This method 2) can be used with any storage, JFFS included, where for USB (only) an alternative is to performed the save/copy within the Run after mounting/Run before unmounting on the USB page instead than the generic script section.

retain_dhcp_lease_info_after_a_reboot.1684891571.txt.gz · Last modified: 2023/05/24 02:26 by hogwild