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, the router needs persistent storage, (such as USB).


There are currently two approaches to resolving this. The first approach does not use scripting.

  1. Under Advanced, go to to DHCP/DNS menu. In the Dnsmasq Custom configuration field, enter:
    dhcp-leasefile=/mnt/usb/dnsmasq/dnsmasq.leases \\ 
  2. Use a path relative to your own system. Click Save.
  3. The goal here is to store the lease database on permanent storage. This can be useful, for example, when devices are connected to a switch. Using permanent storage means client devices won't lose connectivity if the router reboots. Moreover, they won't display in the Device List as having an active lease until their current lease expires, and they request a new one. FreshTomato will just continue where if left off.
  4. You will notice that the example points to a USB device labelled “usb”. You might have a different name on your system, depending on how the storage was formatted. This also means you can store the data on other permanent storage media, such as a CIFS share. However, for these duties, you are advised against using JFFS. It is not recommended for frequent writes (which in this case, would occur every time a new IP is sent).


2) The second approach is to keep the lease database in its default location and copy it to permanent storage at “halt” time. It is later restored when the init process runs during boot.



For example, in the Administration/Scripts menu, in the Init field, enter:

[ -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
}



In the same menu, in the Halt field, enter:

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

This second method can be used with any storage including 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.1684894285.txt.gz · Last modified: 2023/05/24 03:11 by hogwild