What's new

Anyone ever tried to preserve DHCP leases on restart?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

drinkingbird

Part of the Furniture
In theory you could script copy dnsmasq.leases to jffs on shutdown then copy it back on reboot (very early in the reboot process). Anyone ever done it in practice and seen any bad effects of it? I guess the lease time would be a minute or two out of synch with the client but that should update as all the clients will have to renew their leases anyway when the router comes back online, and everything will be back in synch. But it might get confused by that.....
 
You sure you need to do anything at all?

Even if the DHCP server retains no memory of what leases it handed out, the clients know their assigned addresses, and will request renewal of those addresses when they think their lease time is about over. If the DHCP server is cooperative then it'll grant those requests and everything will end up the same. I've actually seen a network mostly retain the same DHCP addresses when I replaced server A with server B with no effort to transfer state to server B.
 
You sure you need to do anything at all?

Even if the DHCP server retains no memory of what leases it handed out, the clients know their assigned addresses, and will request renewal of those addresses when they think their lease time is about over. If the DHCP server is cooperative then it'll grant those requests and everything will end up the same. I've actually seen a network mostly retain the same DHCP addresses when I replaced server A with server B with no effort to transfer state to server B.

Yes, understood, the issue is not clients being able to reconnect or get the same IP after a reboot. This is more to keep a historical list of clients that have connected over the past month without losing them on restart. Obviously not a critical need or big issue, but something other DHCP servers can preserve during a restart (and they adjust the lease time when they reboot so stuff is in synch). Just handy to have.

Yes when a client renews and requests an IP, as long as the IP is available, they'll get the same one (and a fresh lease time), no issue there.
 
DHCP reservation is not an option here?

The lease would still be lost on reboot until the reserved client connected again, and that's a lot of admin overhead especially with some devices using randomized MAC.
 
For that install yazdhcp.

I don't see any reference to preserving the leases on a restart? Does it use jffs to store the bindings?
 
In theory you could script copy dnsmasq.leases to jffs on shutdown then copy it back on reboot (very early in the reboot process). Anyone ever done it in practice and seen any bad effects of it? I guess the lease time would be a minute or two out of synch with the client but that should update as all the clients will have to renew their leases anyway when the router comes back online, and everything will be back in synch. But it might get confused by that.....
I was doing that for years with my N66U and AC68U without any problems. Then I stopped doing it because it seemed kind of pointless.
 
Why don't you disable that on the device for your network?

"Welcome to my house, sure you can use the guest wifi but you must let me go in and disable a security feature on your phone so stores will be able to track you while you shop."
 
I was doing that for years with my N66U and AC68U without any problems. Then I stopped doing it because it seemed kind of pointless.

And I'm realizing in order for it to work during a hard reboot would need a cron job to copy the file every x minutes. Wonder if there is a way to just tell dnsmasq to use jffs for the file in the first place.
 
And I'm realizing in order for it to work during a hard reboot would need a cron job to copy the file every x minutes. Wonder if there is a way to just tell dnsmasq to use jffs for the file in the first place.
Maybe this in a dnsmasq.conf.add file:
Code:
dhcp-leasefile=/jffs/dnsmasq.leases

Code:
-l, --dhcp-leasefile=<path>
    Use the specified file to store DHCP lease information.
 
"Welcome to my house, sure you can use the guest wifi but you must let me go in and disable a security feature on your phone so stores will be able to track you while you shop."
I apologize. I don't remember the "guest network" aspect of what I was replying to.
 
Maybe this in a dnsmasq.conf.add file:
Code:
dhcp-leasefile=/jffs/dnsmasq.leases

Code:
-l, --dhcp-leasefile=<path>
    Use the specified file to store DHCP lease information.

Yeah by "I wonder" I guess I should have said "too lazy to google so far today". Seems since I'm already doing a dnsmasq.postconf I could just add it in there pretty easily. Will toy with it at some point. Even if the client is a couple minutes out of synch as far as lease time they renew long before it expires anyway.
 
Maybe this in a dnsmasq.conf.add file:
Code:
dhcp-leasefile=/jffs/dnsmasq.leases

Code:
-l, --dhcp-leasefile=<path>
    Use the specified file to store DHCP lease information.

So it works, and it starts updating the file on jffs, but unfortunately the GUI must be hardcoded to use the original location as the leases stop updating there. I suppose the only solution is to copy over every so often with a cron job and copy back at services-start.

@RMerlin is the html code hardcoded to pull DHCP lease info from /tmp/var/lib/misc/dnsmasq.leases ?

I did manage to at least simplify the dnsmasq-postconf script for updating the lease time, not needed to read in the config then spit it back out, can just modify the file directly

#!/bin/sh
sed -i "s/86400s/2592000s/" "/etc/dnsmasq.conf"

Actually I'm not entirely sure why that is replacing both instances without the "g" modifier for SED, I accidentally left it off but it works. Added it in just to be safe and consistent and it does the same thing. Odd.
 
Last edited:
@RMerlin is the html code hardcoded to pull DHCP lease info from /tmp/var/lib/misc/dnsmasq.leases ?
If you are referring to existing leases then yes, they are stored in that file. It's not accessed by the HTML page, it's accessed by the httpd daemon, and probably other places within the code, so you shouldn't be messing with that.
 
Delete that file and create a link to /jffs?

The file gets recreated everytime DNSMASQ restarts but I could theoretically script the removal of the file followed by the creation of a symlink (I think, not exactly a linux scripting pro).
 

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top