I'm trying to wrap my head around all the available DNS options.
There are 4 DNS-related configuration areas available:
"Network -> Interfaces -> wan -> Advanced Settings -> Use custom DNS servers"
"Network -> Interfaces -> lan -> Advanced Settings -> Use custom DNS servers"
"Network -> Interfaces -> lan -> DHCP Server -> Advanced Settings -> DHCP Options
"Network -> DHCP and DNS -> DNS Forwardings"
Of the above four only the "DHCP options" (3) makes sense to me. Other options leave a lot of fog in my head around this topic.
I did some forum search and some answers to similar questions say that the DNSs in "wan -> Advanced Settings" and "lan -> Advanced Settings" are used by the router itself.
I'm not sure I understand what exactly that means:
"Router itself" - does it refer to some particular processes running on a router that need DNS?
So does it (the "router itself") use WAN or LAN DNS, after all?
How does "DHCP and DNS" tab fit into the picture, i.e. what is its role?
Might have I missed some wiki/etc section that explains all that? Maybe someone can kindly point me to a description of a DNS request lifecycle in the openWRT world, i.e. from its inception on a connected client, through the entire delegation/forwarding chain with all the pivotal points/possible overrides, to a "final" DNS server?
Yes, several processes, but the needs do depend on how the device is configured (router vs dumb AP, other user installed packages, etc.). The basic processes involve things like NTP (local) functioning as a DNS server in its own right (the default config of OpenWrt will make the router itself the DNS server advertised via DHCP). Of course the opkg package manager needs DNS, and other packages installed by users may need it, too.
The router will use either the forwardings as setup in the dnsmasq config, or the 'upstream' DNS. In the case of router mode, the upstream is almost always the wan -- in this case, any dns servers configured in the lan interface stanza are ignored. This applies either via static IP for the wan or DHCP/PPPoE with the peer-dns disabled (i.e. "don't use the advertised DNS servers"). A dumb AP will use the lan (and there is no wan), so here the lan interface's defined dns server would be used. So it depends on how things are configured.
This allows the admin to set the main system dns and/or selective forwardings for specific domains. It can alternatively be used to configure the system to respect DNS filtering such as AGH or DoH/DoT implementations.
If you're using DHCP option 6, that is not for the router itself, but rather what is advertised to DHCP clients on your network.
I don't see a great OpenWrt specific wiki entry, but the general info is below.
In the meantime, here is another article that kind of describes the DNS process overall (not OpenWrt specific).
Basically, in most configs, the devices behind the OpenWrt router will use OpenWrt as the DNS server... they request a domain resolution and OpenWrt will evaluate the request... if it has the address in cache or in a local resolution table (such as for local hosts), it will respond directly. If not, it will ask the next upstream DNS -- usually this is the ISP's servers or a public one chosen by a user.
It queries all by default and uses the fastest.
You can use strict-order but as said it is not very reliable.
It was used in the past to 'insert' the VPN DNS server when the VPN was on but that proved not very reliable (to make matters worse it also differed by DNSMasq version, if I recall correctly 2.86 was really bad)
For the record to see the conntrack:
cat /proc/net/nf_conntrack | grep -E ' dport=(53|853) '
If your router supports watch:
watch -tn5 "cat /proc/net/nf_conntrack | grep -E ' dport=(53|853) ' | sort -nrk3"
DNSMasq logging: logqueries boolean 0--log-queries=extra Log the results of DNS queries, dump cache on SIGUSR1, include requesting IP
e.g.: option logqueries '1'