Colleagues, please help me understand how the DNS server to which dnsmasq forwards requests from users from the LAN zone is switched "on the fly" in OpenWRT?
My situation is as follows - there is a router, it has WAN and LAN zones. In addition, it can establish a connection to a corporate VPN (OpenVPN).
When the connection to the VPN server is not established, the router must send DNS requests to the provider's servers.
When the connection to the VPN server is established, DNS requests must be sent to the corporate network server so that internal zones are revealed.
In order to set and switch current DNS servers in the current OpenWRT, a certain mechanism is used, but for a person with FreeBSD experience, the logic of its operation is somewhat opaque and not obvious.
Is there any documentation, HOWTO, that describes all these mechanisms and how to manage them?
Each interface can have a set of DNS servers associated to it, be it explicitly on "/etc/config/network", acquired by DHCP, etc.
When an interface comes up, the DNS servers associated to it are written to a file at "/var/resolv.conf.d", and dnsmasq is signaled to reload its configuration. When the interface comes down, the file is erased.
It works as @eduperez explained, unfortunately when a VPN interface comes up the DNS servers are added to the existing DNS servers so you are not exclusively using the VPN DNS servers.
DNSMasq is then choosing the best DNS server that could be your Works DNS server or another.
What you can do is to use DNSMasq address to use a the VPN DNS server for a certain domain. Lets assume the domain of your work is WORK the you add to DNSMasq: address=/WORK/<-IP-of-Work-DNSserver->
In LuCi it is under: Network > DHCP and DNS > General : Addresses
Alternatively use a script to exclusively use the VPN DNS server when the tunnel is up: