DNS Forwarder Issue
Hi, I've been having an issue with a Bind9 DNS forwarder that I can't seem to figure out.
I have a domain, domain.com, that has its DNS hosted by cloudflare. For basic queries to the domain, I allow cloudflare to handle it. However, recently we needed a more complicated solution and require an internal DNS server to handle some new subdomains. So we have a subdomain, sub.domain.com.
In cloudflare, I added an NS record for sub.domain.com. to point to the IP of a public-facing DNS forwarder. This is because our internal DNS server can only be accessed via a VPN. So the forwarder is supposed to take the queries coming for the *.sub.domain.com domain and forward them to the internal name server.
Now for the problem. If I do an nslookup for server.sub.domain.com on a public DNS service (8.8.8.8, for example), I get a SERVFAIL return.
At the same time, if I do an nslookup for server.sub.domain.com but instead of specifying 8.8.8.8 as a DNS server, I directly point to the DNS forwarder, I get a return just fine. This shows that the forwarder and the connection to the internal DNS server is working fine.
Now even more curiously, after I query for server.sub.domain.com directly to the forwarder, queries to 8.8.8.8 for the same domain return fine. This tells me that the forwarder will return cached results but not perform a forward lookup.
The forwarding server is configured with Bind9 with the following configuration:
options {
directory "/var/cache/bind"
dnssec-enable no;
dnssec-validation no;
dnssec-lookaside auto;
allow-query { any; };
allow-query-on { any; };
allow-recursion { any; };
allow-recursion-on { any; };
listen-on { 203.0.113.1; };
};
zone "sub.domain.com" {
type forward;
forward only;
forwarders { 172.16.2.2; };
};
Any ideas as to what would cause this behavior would be greatly appreciated. Thanks.
Posted Dec 24, 2014, 10:05 PM UTC
Maybe 8.8.8.8 isn't setting the recurse flag when it makes the request to your forwarder. When you make the request the flag is set and the forwarder caches it. You could confirm this by using tcpdump to capture traffic on the forwarder as you make the request to 8.8.8.8.
If my theory is correct, you could look up the BIND docs to see if there's a way to always recurse. Or maybe you could forward the requests using iptables and not run a DNS service on the forwarder at all.
It seems you're correct. Queries sent by the 8.8.8.8 responding server have the RD flag set to 0. I'm currently trying to find a setting or something for Bind to ignore this flag and always perform a recursive query if it's not cached.
I had considered using some iptables trickery, however I didn't like the idea of every query having to traverse the VPN adding greatly to latency. The caching on the forwarding server is valuable.
Thank you so much for your help.
This might be a long shot, but could you host your subdomain zone on the forwarder, disable recursion and decommission your internal DNS server?
Another option would be to periodically rsync your zone files from your internal server to the public one.
Whatever you do, make sure your server doesn't forward for domains that it doesn't know about. It would be an open resolver in that case, and those are bad.
One of the banes of the modern internet