Change DNSMasq options on the fly based on svr availability

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Author Message
inetquestion
DD-WRT User


Joined: 24 Sep 2015
Posts: 67

PostPosted: Tue Jul 06, 2021 22:54    Post subject: Change DNSMasq options on the fly based on svr availability Reply with quote
Running piHole on another machine and put the following setting in dnsmasq to issue this server as the DNS server:

6,192.168.0.2

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.

Thanks!
Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12837
Location: Netherlands

PostPosted: Wed Jul 07, 2021 6:48    Post subject: Reply with quote
See second example: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=329571
_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
ho1Aetoo
DD-WRT Guru


Joined: 19 Feb 2019
Posts: 2927
Location: Germany

PostPosted: Wed Jul 07, 2021 9:01    Post subject: Reply with quote
Yes the second example in the sticky thread actually does what you want automatically.

DNS is only a bit slow because it always waits for the timeout of the first DNS server.

But as an emergency solution when the Raspberry is offline it is quite suitable. (mine is running for 168 days and the last reboot was intentional)

Your approach also has its pitfalls, it is often not enough to simply restart dnsmasq, the clients have to renew their DHCP lease as well

Some unruly clients also need to be restarted.

btw DNS leaking is not a problem in the example.
Have never seen advertising leaking
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum