Odhcpd | How to make lease file persistent?

Hi!
I moved the odhcpd lease file to a permanent storage.
But the lease file gets reset/deleted every reboot.
How to make the lease file persistent/survive a reboot?
Thanks.

uci show dhcp
  • Do you need persistent lease file or static DHCPv6 leases?
  • Does the lease file persist after you restart odhcpd?
  • What happens when you stop the service, unmount the file system, and perform soft reboot?

See also DHCP lease file erased while rebooting system

1 Like

uci show dhcp

dhcp.odhcpd=odhcpd
dhcp.odhcpd.maindhcp='1'
dhcp.odhcpd.leasefile='/mnt/sda1/odhcpd/dhcp.leases'
dhcp.odhcpd.leasetrigger='/usr/lib/unbound/odhcpd.sh'
dhcp.odhcpd.loglevel='3'
dhcp.lan=dhcp
dhcp.lan.interface='lan'
dhcp.lan.dhcpv4='server'
dhcp.lan.dhcpv6='server'
dhcp.lan.ra='server'
dhcp.lan.ra_default='1'
dhcp.lan.ra_management='1'
dhcp.lan.force='1'
dhcp.lan.start='100'
dhcp.lan.limit='99'
dhcp.lan.leasetime='8d'
dhcp.lan.domain='lan'
dhcp.wan=dhcp
dhcp.wan.interface='wan'
dhcp.wan.ignore='1'
dhcp.@host[0]=host
dhcp.@host[0].name='Host 1'
dhcp.@host[0].mac='xx:xx:xx:xx:xx:xx'
dhcp.@host[0].duid='00000000000000000000'
dhcp.@host[0].ip='10.0.0.1'
dhcp.@host[0].hostid='1'
dhcp.@host[1]=host
dhcp.@host[1].name='Host 2'
dhcp.@host[1].mac='xx:xx:xx:xx:xx:xx'
dhcp.@host[1].ip='10.0.0.10'
dhcp.@host[2]=host
dhcp.@host[2].name='Host 3'
dhcp.@host[2].mac='xx:xx:xx:xx:xx:xx'
dhcp.@host[2].duid='00000000000000000000'
dhcp.@host[2].ip='10.0.0.50'
dhcp.@host[2].hostid='50'
dhcp.@host[3]=host
dhcp.@host[3].name='Host 3'
dhcp.@host[3].mac='xx:xx:xx:xx:xx:xx'
dhcp.@host[3].ip='10.0.0.250'

Both

No

Haven't tried this yet.

I’m curious about the need for a persistent lease database. DHCP practice is generally to reserve IP addresses for hosts that need stable IPs, and use the pool for the rest.

A well-behaved client will ask to renew its IP address and a well-behaved server will grant the request unless it has been reassigned already.

1 Like

odhcpd doesn't retain state. Yes, you can move the file around, but as far as odhcpd is concerned, the file is write-only - it never reads it back.

The real solution is still the same as the previous answer for dnsmasq, if you want static lease, then define them properly - instead of relying on the perceived persistency of dynamic leases.

3 Likes

The static leases work fine.
The "problem" is after reboot some devices (the ones that aren't directly connected, because their interfaces don't go into disconnect state and request a new lease immediately) don't show up on the overview page.
If a long lease time is used it takes a good amount of time until the devices send a renew request and showing up on the overview page again. Using a shorter lease time of 1h for example works but having odhcpd just read the lease file again would be great.

Why is ip6hint removed from luci in latest trunk?

Not intentionally, will look

Edit: fixed with https://github.com/openwrt/luci/commit/3734f88c3588600bb03a2a413b2f3979ff5a07cf

2 Likes

Thank you.