how to setup dnsmasq for DNS for private and public hostnames via different DNS servers [duplicate]

lets say i have this private hostname dev.private.example.com that is only accessible in a private network over VPN connection and i have prod.example.com that is accessible to the internet. I have DNS servers to resolve the private hostname and then i can use the public DNS servers(google, cloudflare etc) for the public hostnames.

i will like setup dnsmasq(let me know if there is another tool) so that it will query DNS server for the private hostnames and if it is another hostname then it will resolve via the public DNS servers

How do i go about doing this?


Solution 1:

this is what worked for me

edit /etc/dnsmasq.conf and have this in the file

conf-dir=/etc/dnsmasq.d/,*.conf

and then create a file in the conf directory /etc/dnsmasq.d/private.example.com.conf

and add the following in the content of the file


#dont use hosts nameservers
no-resolv
#use following default nameservers
server=1.1.1.1
server=8.8.8.8
strict-order
#serve all *.private.example.com queries using a specific nameserver
server=/private.example.com/140.82.113.1
server=/private.example.com/140.82.113.2

where the following are the nameservers 140.82.113.1 and 140.82.113.2 resolving the private hostname

then restart dnsmasq

service restart dnsmasq

now any private hostnames *.private.example.com will use those nameservers to resolve!!!

and boom!!!