What's new

Proper dnsmasq config for local resolver?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

XxUnkn0wnxX

New Around Here
Hi, i'm not sure how to ask this or if this has been asked, I want to have

Code:
nameserver 127.0.0.1
at the top of resolv.conf every boot.

now my WAN DNS Setting has
Code:
1.1.1.1
208.67.222.222

and it doesn't allow for a 3rd or 4th and so forth name servers to be listed only 2.

I want to be able to have proper DNS caching so that my routers dnsmasq is where all quires hit before being forwarded down to CF DNS and so forth.
as i have some custom DNS domains pointing to my own hosts which I have added to: /jffs/configs/dnsmasq.conf.add

now i have added this to /jffs/scripts/services-start

Code:
# Add local DNS server to resolv.conf
/bin/sh /jffs/scripts/dns_resolver.sh

and: /jffs/scripts/dns_resolver.sh
Code:
#!/bin/sh
# Delay execution
sleep 20

# Add local DNS server to resolv.conf if not already present
if ! grep -q "nameserver 127.0.0.1" /etc/resolv.conf; then
    echo -e "nameserver 127.0.0.1\n$(cat /etc/resolv.conf)" > /etc/resolv.conf
fi

# Add local DNS server to /tmp/resolv.dnsmasq if not already present
if ! grep -q "server=127.0.0.1" /tmp/resolv.dnsmasq; then
    echo -e "server=127.0.0.1\n$(cat /tmp/resolv.dnsmasq)" > /tmp/resolv.dnsmasq
fi

# Restart dnsmasq service to apply changes
service restart_dnsmasq

now I think my implementation of it is a bit dirty, is there a proper way to do this? append additional name servers at the top of resolv.conf & ensure that dnsmasq uses it?

I noticed that dnsmasq has the setting: no-resolv enabled which stops it from using /etc/resolv.conf
that's why I added the server=127.0.0.1 to /tmp/resolv.dnsmasq as well.
 
I want to be able to have proper DNS caching so that my routers dnsmasq is where all quires hit before being forwarded down to CF DNS and so forth.
Having three server lines in resolv.conf will not achieve that. You need only a single line for 127.0.0.1. This is what the option Tools - Other Settings > Wan: Use local caching DNS server as system resolver = Yes does.
 
And the tooltip for Wan: Use local caching DNS server as system resolver (default: No):
tooltip.jpg
 
Having three server lines in resolv.conf will not achieve that. You need only a single line for 127.0.0.1. This is what the option Tools - Other Settings > Wan: Use local caching DNS server as system resolver = Yes does.
And the tooltip for Wan: Use local caching DNS server as system resolver (default: No):
View attachment 59954
thanks did not see this, as the clients were hitting dnsmasq but router didn't.
 

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top