Site Tools


retain_dhcp_lease_info_after_a_reboot

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
retain_dhcp_lease_info_after_a_reboot [2023/05/24 02:57] – -condense, formatting hogwildretain_dhcp_lease_info_after_a_reboot [2023/08/15 18:32] (current) – [Method 2: Copying the lease database to permanent storage at halt time] petervdm
Line 1: Line 1:
 ====== Retain DHCP Lease Information after a Reboot ====== ====== Retain DHCP Lease Information after a Reboot ======
  
-By default, dnsmasq stores DHCP lease information in RAM. This means that operations like 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, your router needs persistent storage, (such as USB).+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.
  
-There are currently two approaches to resolving this. The first approach does not use scripting. 
  
-  - Under Advanced, go to to [[:advanced-dhcpdns|DHCP/DNS]] menu. In the //Dnsmasq Custom configuration// field, enter: \\ <code -> +===== Method 1Store the lease database on permanent storage ====
-dhcp-leasefile=/mnt/usb/dnsmasq/dnsmasq.leases \\  + 
-</code> +The first method does not use scripting. The goal of the first method is to store the lease database on permanent storage.
-  - Use a path relative to your own system Click Save. \\  +
-  - 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 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 points to a USB device with label "usb". You might have different names on your system, depending on how the storage was formatted. This also means you can store the data on different permanent storage, such as a CIFS share. However, for this specific operation, you are not advised to use 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 "initat boote.g.+  - Under Advanced, go to the [[advanced-dhcpdns|DHCP/DNS/TFTP]] menu. In the //Dnsmasq Custom configuration// field, enter: \\ \\ <code -> 
 +dhcp-leasefile=/mnt/usb/dnsmasq/dnsmasq.leases 
 +</code> \\  
 +  - Use a path relative to your own system.  Click Save. \\ \\  
 +  - Using permanent storage means client devices won't lose connectivity if the router reboots. Because the lease database is not stored in RAM, a reboot won't erase it. This can be useful, for example, when devices are connected to a switch. Moreover, clients won't display in the [[status-devices|Device List]] 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 labelled "usb"You might have a different name on your system, depending on how storage was formattedThis also means you can store the data on other permanent media, like a CIFS share. However, for such configurations, it is 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).
  
-Administration/Scripts/Init\\+ 
 +===== Method 2: Copying the lease database to permanent storage at halt time ===== 
 + 
 +\\ 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 Init field in the [[admin-scripts|Scripts]] menu, enter:\\
  
 <code -> <code ->
 [ -f /mnt/usb/dnsmasq.leases ] && { [ -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 /tmp/var/lib/misc/dnsmasq.leases > /tmp/dnsmasq.tmp1 
- sort -b -k 2 -u -z /mnt/usb/dnsmasq.leases > /tmp/dnsmasq.tmp2 +sort -b -k 2 -u -z /mnt/usb/dnsmasq.leases > /tmp/dnsmasq.tmp2 
- diff -a /tm +diff -a /tmp/dnsmasq.tmp1 /tmp/dnsmasq.tmp2 | grep -E '^>' | sed 's/^>\ //' >> /tmp/var/lib/misc/dnsmasq.leases 
- kill -HUP `ps | grep  +kill -HUP `ps | grep -E [d]nsmasq | awk '{ print $1 }'` 
- rm /tmp/dnsmasq.tmp1 +rm /tmp/dnsmasq.tmp1 
- rm /tmp/dnsmasq.tmp2+rm /tmp/dnsmasq.tmp2 
 +rm -f /mnt/usb/dnsmasq.leases
 } }
 </code> </code>
  
-Administration/Scripts/Halt\\+ \\ 
 + 
 + \\ 
 + 
 +in the //Halt// field In the [[admin-scripts|Scripts]] menu, enter:\\
  
 <code -> <code ->
Line 37: Line 48:
 </code> </code>
  
-This method 2can be used with any storage, JFFS included, where for USB (onlyan alternative is to performed the save/copy within the ''Run after mounting/Run before unmounting'' on the [[nas-usb|USB page]] instead than the generic script section.+ \\ 
 + 
 + \\ 
 + 
 +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. 
 + 
 + \\ 
 + 
 + \\
  
  
retain_dhcp_lease_info_after_a_reboot.1684893442.txt.gz · Last modified: 2023/05/24 02:57 by hogwild