====== Retain DHCP Lease Information after a Reboot ====== By default, dnsmasq stores DHCP lease data in (volatile) 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 client 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 common methods for dealing with this. ===== Method 1: Store the lease database on permanent storage ===== The first method doesn't use scripting. Its goal is to store the lease database on permanent storage. \\ - Under Advanced, go to the [[advanced-dhcpdns|DHCP/DNS/TFTP]] 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. \\ \\ - Using permanent storage lets clients maintain connectivity after router reboots.\\ Because the lease database isn't stored in RAM, rebooting won't erase it. \\ This can be useful when devices are connected to a switch. \\ \\ As well, clients in the [[status-devices|Device List]] won't show as having an active lease \\ until their current lease expires, and they've requested a new one. \\ FreshTomato will just continue where if left off. \\ \\ - Notice that the example points to a USB device named "usb". \\ Yours may have a different name, depending on how storage was formatted. \\ This also means you can store the data on other permanent media, such as \\ a CIFS share. \\ \\ However, for such configurations, it's not wise to use JFFS. JFFS is not\\ recommended for frequent writes (which, in this case, would occur every \\ time a new IP is sent). ===== Method 2: Copying the lease database to permanent storage at halt time ===== The second approach keeps the lease database in its default location and copies it to permanent storage at "halt" time. It is later restored when the init process runs during boot. \\ \\ For example, in the Init field in the [[admin-scripts|Scripts]] menu, 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 /tmp/dnsmasq.tmp1 /tmp/dnsmasq.tmp2 | grep -E '^>' | sed 's/^>\ //' >> /tmp/var/lib/misc/dnsmasq.leases kill -HUP `ps | grep -E [d]nsmasq | awk '{ print $1 }'` rm /tmp/dnsmasq.tmp1 rm /tmp/dnsmasq.tmp2 rm -f /mnt/usb/dnsmasq.leases } \\ \\ in the //Halt// field In the [[admin-scripts|Scripts]] menu, enter:\\ cp -f /tmp/var/lib/misc/dnsmasq.leases /mnt/usb/dnsmasq.leases \\ \\ Method 2 can be used with any type of storage, including JFFS. When using method 2 only with USB, an alternative is to enter the former set of configuration lines into the //Run after mounting// field and the latter set of lines in the //Run before unmounting// fields in the [[nas-usb|USB Support]] menu. \\ \\