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
Next revisionBoth sides next revision
retain_dhcp_lease_info_after_a_reboot [2022/02/04 03:23] hogwildretain_dhcp_lease_info_after_a_reboot [2023/08/09 15:32] – [Method 1: Store the lease database on permanent storage] -grammar hogwild
Line 1: Line 1:
 ====== Retain DHCP Lease Information after a Reboot ====== ====== Retain DHCP Lease Information after a Reboot ======
  
-In order for dnsmasq to maintain its DHCP lease information, persistent storage, (such as USB) is needed.  This isn't a scripting method/example //per se//. It may not be what you're looking for.+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).
  
-Navigate to [[:advanced-dhcpdns|DHCP/DNS]] under the Advanced menu In the **//Dnsmasq Custom configuration//** field, enter:+There are currently two common methods for dealing with this. 
 + 
 + 
 +===== Method 1Store the lease database on permanent storage ===== 
 + 
 +The first method does not use scriptingThe goal of the first method 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: \\ \\ <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. \\ \\  
 +  - 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 storage was formatted. This 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).
 +
 +
 +===== 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 in the Init field on the [[admin-scripts|Scripts]] menu, enter:\\
  
 <code -> <code ->
-dhcp-leasefile=/opt/var/dnsmasq/dnsmasq.leases+-/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 
 +}
 </code> </code>
  
  \\  \\
  
-Use a path relative to your own system.  Click Save.+ \\
  
-This can be usefulfor example, when devices are connected to a switchThey 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.+in the //Halt// field In the [[admin-scripts|Scripts]] menu, enter:\\ 
 + 
 +<code -> 
 +cp -f /tmp/var/lib/misc/dnsmasq.leases /mnt/usb/dnsmasq.leases 
 +</code> 
 + 
 + \\ 
 + 
 + \\ 
 + 
 +Method 2 can be used with any type of storageincluding JFFSWhen using USB (only)an alternative is to enter the above configuration lines into the //Run after mounting// or //Run before unmounting// fields on the [[nas-usb|USB Support]] page. 
 + 
 + \\ 
 + 
 + \\
  
  
retain_dhcp_lease_info_after_a_reboot.txt · Last modified: 2023/08/15 18:32 by petervdm