So I have an interesting home network setup: I wanted to protect my kids' devices from the filth found all over the internet, so I did the following:
- Setup DNSCrypt-Proxy on loopback port 5353, and pointed it at AdGuard Family Shield DNS server.
- Enable DNSMasq as the local DNS server broadcasted over DHCP.
- Disable ISP supplied DNS Servers, and force all DNS requests coming in to DNSMasq to be forwarded to DNSCrypt-Proxy.
So this way, EVERY device on my network will be routed through family safe DNS Servers (yes, even if you try to go to, say, 126.96.36.199, my firewall rules will catch that and re-route accordingly).
I found this to be a great solution for my children and my peace of mind, but bit too restrictive for the wife and myself. We do want to be able to browse adult content, BUT only on a restricted set of devices, explicitly enabled one by one.
So I further modified my network setup in following ways:
- Created 2nd instance of DNSCrypt-Proxy on loopback port 5354, and point it at Adguard DNS Server (which only blocks ads, nothing more)
- Assigned static IPs to the 5 devices on my home network which I want to have unrestricted DNS query access.
- Finally, created firewall rules (listed below) to route the 5 specific devices STRAIGHT to DNSCrypt-Proxy on port 5354, followed by more rules that capture ALL OTHER DNS traffic and route it to DNSMasq on the router, which in turn forwards to safe DNS server.
I hope this clearly describes my setup.
Now here is the problem I have:
My laptop, with has its DNS requests routed to DNSCrypt-Proxy on port 5354, BYPASSING DNSMasq, can no longer resolve local hostnames. Whereas other lan clients can, because they go through DNSMasq which knows about the hostnames on the lan from DHCP requests. So basically the DNSCrypt-Proxy instance meant for my unrestricted devices is completely unaware of other hosts on the lan.
How can I fix this? Ideally without adding entries to the routers /etc/hosts file. How can I make local DNSCrypt instance be able to resolve LAN hostnames?
Thank you for reading this far!
Firewall rules below.
BTW, I had to put this "echo 1 > /proc/sys/net/ipv4/conf/br-lan/route_localnet" command in my /etc/rc.local to enable routing from br-lan to loopback interface. without it the rules forwarding unrestricted DNS queries to 127.0.0.1:5354 were doing NOTHING.
UNRESTRICTED_CLIENTS="-m iprange --src-range 192.168.1.10-192.168.1.14"
iptables -t nat -A zone_lan_prerouting -p tcp $UNRESTRICTED_CLIENTS --dport 53 -j DNAT --to $UNRESTRICTED_DNS
iptables -t nat -A zone_lan_prerouting -p udp $UNRESTRICTED_CLIENTS --dport 53 -j DNAT --to $UNRESTRICTED_DNS
iptables -t nat -A zone_lan_prerouting -p tcp $RESTRICTED_CLIENTS --dport 53 -j DNAT --to $RESTRICTED_DNS
iptables -t nat -A zone_lan_prerouting -p udp $RESTRICTED_CLIENTS --dport 53 -j DNAT --to $RESTRICTED_DNS