I see that by default the dnsmasq leasefile is in /tmp/leasefile. This means that on a router restart (which happens rarely when I'm troubleshooting, but it's still something that does happen), because the file is lost, all wifi devices renew dhcp leases but wired ones don't. This has the sideeffect that ethers defined dns addresses such as my-host.lan no longer resolves to the correct ip, even if the host is still holding to that ip, because the leasetime isn't over and it does not need to renew yet.
Moving the leasefile to a non-temporary directory should mean on a reboot it is read, and state is not lost. However, I'm here going, if it was this simple, I feel that'd be the default behavior. Am I missing something here? Would this be a good idea or come with serious downsides? Perhaps another question is, what's the justification for the current setup being the default?
Yes, I am using static leases, as I had mentioned as the ethers file. The issue is that, on a reboot, openwrt loses track of the active dhcp lease, and doesn't actually resolve my-host.lan to the static lease ip, until the host renews the dhcp lease.
For anyone running on platforms with more durable storage (e.g. x86 or rpi), it is entirely possible to move the dhcp.leases file to /etc and then symlink that file to /tmp/dhcp.leases.
I do this on my x86_64 platform so my leases file survives reboots. I have also added /etc/dhcp.leases to my /etc/sysupgrade.conf so it survives upgrades as well.
To create the necessary symlink upon every reboot, you’d want to add this to your /etc/rc.local file:
# Create a symlink to /etc/dhcp.leases if it doesn't exist already...
[ ! -f /tmp/dhcp.leases ] && ln -s /etc/dhcp.leases /tmp/dhcp.leases || echo "INFO: /tmp/dhcp.leases already exists."
A static lease, defined in the ethers file, maps a mac address to a custom name and a static ip. This way, name.lan gets mapped to the ip (as dnsmasq handles both dns and dhcp, it can easily integrate these), as long as there is an active dhcp lease (which is what I discovered at least, and the root of my problem).
This is not applicable for me, due to not having durable storage, but still wanted to ask why you go with a symlink setup at startup rather than just change the relevant config option?
The documentation for uci based configuration actually exposes all of these options. Maybe interesting to check (tho it's just examples, not explained in detail. For that, it's best to look into further documentation of the underlying tooling and the generated files)
Because I have some other tools that are looking at /tmp/dhcp.leases and are not set up to follow that config option. But if that same situation doesn’t apply to another, then by all means the config option would be the way to go.
I use option dhcphostsfile '/etc/config/dhcp.hosts' , and when I edit this file, I run a script that copy the entries to /etc/hosts file . This way my dns always translate, with or without an active dhcp lease
Edit:
In dhcp.hosts, the entry is something like this: XX:XX:XX:XX:XX:XX,192.168.21.141,note
On a small network it doesn't hurt to use short lease times like 10 minutes. Should the router reboot the clients will send renewals which will repopulate the RAM disk table within a few minutes.