drinkingbird
Part of the Furniture
If you want DHCP leases to be preserved after a restart (mostly for auditing and historical data, since clients will typically get the same IP after a reboot even if the lease is no longer present), it is relatively straightforward.
Also, optional configs to extend your LAN lease time beyond the 7 day limit in the GUI, and/or extend the Guest Network 1 lease beyond the 1 day default (which can't be changed in the GUI).
### Go to the very bottom for the short version that sets all your leases to 30 days and has them survive a reboot.
This is on my RT-AC1900 (RT-AC68U variant). Should work on others, but you'll need to check if the setup is the same and/or test it out.
First, let's preserve your current lease table and move it to JFFS:
(or put it in a subdirectory of jffs if you want)
Now create a script in /jffs/scripts named dnsmasq.postconf
If you used a subdirectory when copying above, update the below to match that
Then like any script do
Now do
All set, leases will be kept after a reboot. Technically each reboot will make them a couple minutes out of synch with the client, but since every cilent will renew upon router reboot (or when the client comes online next), it will synch back up.
_____________________________________________________________________________________________________________________________
If you want to extend your lease time beyond the 7 day max for LAN, or the 1 day hardcoded default for Guest Wireless 1:
Create a script called services-start in /jffs/scripts if you don't already have one
If you want something other than 30 days, you can use that, but it must be specified in SECONDS
If all you want to change is the main LAN lease time (or you aren't using Guest Wireless 1) skip to
If you're changing Guest Wireless 1 also, include these two below (again, use whatever value you want in seconds)
Note that these 2 values don't appear to actually get used anywhere, but just in case they do (or do in the future) can't hurt to update them
If all you want to do is the main LAN (or you aren't using Guest Wireless 1) above is all you need.
Again do
This won't take effect until you reboot the router, (or you could run the script manually and restart dnsmasq if you don't want to reboot, the script will be used next time you reboot)
The router GUI DHCP settings will reflect the 2592000 lease time, but if you try to edit it in the GUI, you'll see it won't let you unless you drop it back to 7 days or less.
If you want to adjust the Guest Wireless 1 Pools - continue below
Add below in the same dnsmasq.postconf script that was created earlier to change the lease file location:
Below will update all 1 day lease times to 30 days (specifically targeting the guest wireless 1 pools here since they are hardcoded to 1 day)
**If your main LAN is set to 1 day lease time, this will update that to 30 days also. Make sure you're using something other than 1 day (86400) for LAN, or set it to 86399 or 86401 in the GUI if you want LAN to keep 1 day.
The LAN should not be adjusted with this script, it should be done via the GUI for up to 7 days, or via the NVRAM script above for over 7 days.
If you want something other than 30 days (less or more), convert it to seconds and put it in place of 2592000
Technically you can specify days in the format like "30d" instead of "2592000s" but I wanted to stay with what the router does by default
Again do
To test everything is working right, you can reboot the router and you should see the leases are all still there, and are showing 30 days or whatever you chose. You can SSH in and verify that the symbolic link is still in place and the file on JFFS is getting updated (timestamp will update when you do a renew on any client).
###############################################################################################################
Below is the full config to set all DHCP pools to 30 day lease times, and have the leases survive a reboot by putting them in the root of /jffs:
services-start script:
dnsmasq.postconf script:
Now do
Also, optional configs to extend your LAN lease time beyond the 7 day limit in the GUI, and/or extend the Guest Network 1 lease beyond the 1 day default (which can't be changed in the GUI).
### Go to the very bottom for the short version that sets all your leases to 30 days and has them survive a reboot.
This is on my RT-AC1900 (RT-AC68U variant). Should work on others, but you'll need to check if the setup is the same and/or test it out.
First, let's preserve your current lease table and move it to JFFS:
cp /tmp/var/lib/misc/dnsmasq.leases /jffs/dnsmasq.leases
(or put it in a subdirectory of jffs if you want)
Now create a script in /jffs/scripts named dnsmasq.postconf
If you used a subdirectory when copying above, update the below to match that
#!/bin/sh
#Replace the default lease file with a symbolic link to one on JFFS so it survives a reboot
ln -sf /jffs/dnsmasq.leases /tmp/var/lib/misc/dnsmasq.leases
Then like any script do
chmod a+rx /jffs/scripts/*
to make it executableNow do
service restart_dnsmasq
All set, leases will be kept after a reboot. Technically each reboot will make them a couple minutes out of synch with the client, but since every cilent will renew upon router reboot (or when the client comes online next), it will synch back up.
_____________________________________________________________________________________________________________________________
If you want to extend your lease time beyond the 7 day max for LAN, or the 1 day hardcoded default for Guest Wireless 1:
Create a script called services-start in /jffs/scripts if you don't already have one
#!/bin/sh
#Set the Main LAN lease time to 30 days
nvram set dhcp_lease=2592000
If you want something other than 30 days, you can use that, but it must be specified in SECONDS
If all you want to change is the main LAN lease time (or you aren't using Guest Wireless 1) skip to
nvram commit
belowIf you're changing Guest Wireless 1 also, include these two below (again, use whatever value you want in seconds)
Note that these 2 values don't appear to actually get used anywhere, but just in case they do (or do in the future) can't hurt to update them
nvram set lan_lease=2592000
nvram set lan1_lease=2592000
nvram commit
If all you want to do is the main LAN (or you aren't using Guest Wireless 1) above is all you need.
Again do
chmod a+rx /jffs/scripts/*
to make it executableThis won't take effect until you reboot the router, (or you could run the script manually and restart dnsmasq if you don't want to reboot, the script will be used next time you reboot)
The router GUI DHCP settings will reflect the 2592000 lease time, but if you try to edit it in the GUI, you'll see it won't let you unless you drop it back to 7 days or less.
If you want to adjust the Guest Wireless 1 Pools - continue below
Add below in the same dnsmasq.postconf script that was created earlier to change the lease file location:
Below will update all 1 day lease times to 30 days (specifically targeting the guest wireless 1 pools here since they are hardcoded to 1 day)
**If your main LAN is set to 1 day lease time, this will update that to 30 days also. Make sure you're using something other than 1 day (86400) for LAN, or set it to 86399 or 86401 in the GUI if you want LAN to keep 1 day.
The LAN should not be adjusted with this script, it should be done via the GUI for up to 7 days, or via the NVRAM script above for over 7 days.
If you want something other than 30 days (less or more), convert it to seconds and put it in place of 2592000
Technically you can specify days in the format like "30d" instead of "2592000s" but I wanted to stay with what the router does by default
#Replace all 1 day lease times with 30 days
sed -i "s/86400s/2592000s/g" "/etc/dnsmasq.conf"
Again do
service restart_dnsmasq
unless you're going to do the reboot below right away.To test everything is working right, you can reboot the router and you should see the leases are all still there, and are showing 30 days or whatever you chose. You can SSH in and verify that the symbolic link is still in place and the file on JFFS is getting updated (timestamp will update when you do a renew on any client).
###############################################################################################################
Below is the full config to set all DHCP pools to 30 day lease times, and have the leases survive a reboot by putting them in the root of /jffs:
cp /tmp/var/lib/misc/dnsmasq.leases /jffs/dnsmasq.leases
services-start script:
#!/bin/sh
nvram set dhcp_lease=2592000
nvram set lan_lease=2592000
nvram set lan1_lease=2592000
nvram commit
dnsmasq.postconf script:
#!/bin/sh
sed -i "s/86400s/2592000s/g" "/etc/dnsmasq.conf"
ln -sf /jffs/dnsmasq.leases /tmp/var/lib/misc/dnsmasq.leases
Now do
chmod a+rx /jffs/scripts/*
and then reboot the router.