Joined: 05 Oct 2008 Posts: 666 Location: Helsinki, Finland / nr. Alkmaar, Netherlands
Posted: Sat Aug 01, 2020 6:46 Post subject: How to retrieve value of DNSMasq option server=?
Is there a way to retrieve the value of the additional DNSMasq option
server=192.168.x.abc
There are several nvram variables which contain the correct value, but all look like they are 'derived', e.g.
ath1.1_dns_ipaddr=192.168.5.60
Executing
nvram show | grep server
in an ssh session, will give me
...
# PiHole DNS server
server=192.168.5.60
server=fe80::6b0a:7473:53ae:761c
...
which are a few lines from my Additional DNSMasq options field.
(obviously having two server= options likely means that 'server' cannot be an nvram or memory variable as such)
echo $server gives me an empty line, just as
echo $(nvram get server).
root@R7800:~# echo $server
root@R7800:~# echo $(nvram get server)
root@R7800:~# echo $(nvram get br2_dns_ipaddr)
192.168.5.60
would be ok, but br2_dns_ipaddr is 'derived' from the original setting somehow and I may not always have a br2, nor br1.
However, br0_dns_ipaddr, which I assume would always be present, does not exist ...
In my firewall script I was able to use:
ROUTER_IP=$(nvram get lan_ipaddr)
and refer to that variable in the actual rules, and that's the kind of thing I'd like to do for DNS IP as well.
Joined: 16 Nov 2015 Posts: 6447 Location: UK, London, just across the river..
Posted: Sat Aug 01, 2020 12:02 Post subject:
if i got you correctly...my 2 cents
by default DNSmasq serves all interfaces...but if you specify interface it gets more specific..
interface=br0 so you can add interface= to all interfaces you want to mention only...
to find witch servers are in use
cat /proc/net/ip_conntrack | grep 'dport=53 '
cat /tmp/resolv.dnsmasq - shows DNSmasq serves used too..
or any other port you've chosen (this command might not work on all routers)
to see DNSmasq cache entries- cat /tmp/DNSCache.log
but you have to activate the logging in DNSmsaq
cat /tmp/dnsmasq.conf - shows DNSmsaq config
another one more advanced command for high grade routers
cat /proc/net/ip_conntrack | grep -Eo "^udp [^s]*src=$(nvram get wan_ipaddr) .*" | grep -Eo '^.*dport=53 ' | sort -k3,3rn _________________ Atheros
TP-Link WR740Nv1 ---DD-WRT 55630 WAP
TP-Link WR1043NDv2 -DD-WRT 55723 Gateway/DoT,Forced DNS,Ad-Block,Firewall,x4VLAN,VPN
TP-Link WR1043NDv2 -Gargoyle OS 1.15.x AP,DNS,QoS,Quotas
Qualcomm-Atheros
Netgear XR500 --DD-WRT 55779 Gateway/DoH,Forced DNS,AP Isolation,4VLAN,Ad-Block,Firewall,Vanilla
Netgear R7800 --DD-WRT 55819 Gateway/DoT,AD-Block,Forced DNS,AP&Net Isolation,x3VLAN,Firewall,Vanilla
Netgear R9000 --DD-WRT 55779 Gateway/DoT,AD-Block,AP Isolation,Firewall,Forced DNS,x2VLAN,Vanilla
Broadcom
Netgear R7000 --DD-WRT 55460 Gateway/SmartDNS/DoH,AD-Block,Firewall,Forced DNS,x3VLAN,VPN
NOT USING 5Ghz ANYWHERE
------------------------------------------------------
Stubby DNS over TLS I DNSCrypt v2 by mac913
Anything specified in the Additional DNSMasq Options field ultimately ends up in the DNSMasq config file, so you can just grep that file rather than searching nvram (which can sometimes be difficult given the way things are encoded).
Joined: 05 Oct 2008 Posts: 666 Location: Helsinki, Finland / nr. Alkmaar, Netherlands
Posted: Sun Aug 02, 2020 6:50 Post subject:
I haven't had too much time to try the commands Alozaros proposed, but also from earlier experience I knew that there's no such file on my R7800 as ip_conntrack. Instead I found a file called np_conntrack, which looks like it contains similar information (on which the active connections table seems to be based).
The most elaborate command
cat /proc/net/ip_conntrack | grep -Eo "^udp [^s]*src=$(nvram get wan_ipaddr) .*" | grep -Eo '^.*dport=53 ' | sort -k3,3rn
I couldn't get to produce anything even after changing the filename. I then tried it up to and including the first grep, but no dice. There are no lines starting with udp in that file.
And then it was time for bed ...
after noticing the latest 44044 had been pulled and checking if the problem with that build may concern the R7800, too.
Joined: 05 Oct 2008 Posts: 666 Location: Helsinki, Finland / nr. Alkmaar, Netherlands
Posted: Mon Aug 03, 2020 19:38 Post subject:
yoyoma2 wrote:
Have you tried variable dnsmasq_options? That's what easyddup uses to save/restore "Additional Dnsmasq Options".
Code:
nvram get dnsmasq_options
I have now ... Thanks!
To actually retrieve the value I want - out of the two available, IPv4 and IPv6 ... - I would also need grep, and then something like awk, I think. I have a copycatted example somewhere where I dissect a string, but no inspiration at the moment to find it and then make it work here. It would quickly become overly complicated, since I am the only one controlling this LAN & router and if I ever want to change the DNS server's address, I'm sure I will be able to find all occurences.
It just brings some neatness to any script, if there aren't a million copies of a constant ...