Posted: Tue Jul 06, 2021 22:54 Post subject: Change DNSMasq options on the fly based on svr availability
Running piHole on another machine and put the following setting in dnsmasq to issue this server as the DNS server:
Occasionally piHole goes down and everything on the network is fubar until it comes back up or the DHCP options are modified to point somewhere else. Yes, I could list both DNS servers, but I don't want traffic leaking to the alternate server while the primary is up/working.
Wrote a script which checks if the DNS server is up AND which server dnsmasq is currently handing out by checking: "nvram get dnsmasq_options". If PiHole is down, cmd is issued to update nvram variable accordingly. This all works as described. The part that doesn't work is clients who renew their DHCP lease do not get the new value. In dd-wrt gui, if the services page is reloaded, can see the new value from the script did get updated. Seems I need to click the 'apply settings' button somehow.
Looked into restarting dnsmasq from within the script, but looking at the current running process, it is getting config from /tmp/dnsmasq.conf as shown below. What caused this to be written here?
ps -w | grep -i dns
2221 root 1804 S dnsmasq -u root -g root -C /tmp/dnsmasq.conf
Examining that file shows the old value is still in there, not the updated value shown in the gui. Other than rebooting the router, is there another way to make the change take effect?
As a laugh, I considered running that file through SED, then restart, but guessing there is another much better way to do this...
Can post the script if anyone is interested, but didn't seem relevant to the question at this point.