I have a network of instances. Most of them are using the default VPC’s DNS resolver to prevent exfiltration and to resolve internal domains (using a custom TLD). That all works fine.
However, there is one (Ubuntu) instance that needs to use a general, public resolver to reach the Internet at large (e.g. 8.8.8.8)
I managed to get this work in us-east-1 by replacing /etc/systemd/resolved.conf with
[Resolve]
DNS=8.8.8.8 208.67.222
and adding an /etc/systemd/resolved.conf.d/MYTLD.conf
[Resolve]
Domains=MYTLD
DNS=10.6.0.2
After restarting systemd-resolved, the instance resolves all domains just fine.
But when I apply this exact same configuration to a nigh-identical network in us-east-2, public DNS doesn’t work.
One suggestion I found on StackExchange was to symlink /etc/resolv.conf to /run/systemd/resolve/resolv.conf, which fixed public DNS but broke the internal
Can anyone provide any insight on how to fix this?
Yes, but we’ve set it to default deny for this VPC. All the other instances only need to be able to resolve a small allow-list of known domains; basically just the mail server needs to be able to access arbitrary ones.
Okay gotcha. Are you sure the traffic can get to the internet? You have the correct routes, NACLs, etc? Might try using the VPC Reachability Analyzer to double check if you’re certain the OS DNS configuration is correct.
If you look at VPC flow logs, do you see your queries going to the right place? Does your manual test and your configured test produce the same flow log results?
VPC configuration isn’t the problem then, if you can resolve from the command line. Are the editions of Ubuntu the same? Split DNS is not a feature that all editions of Ubuntu have
So I’ve never messed with flow logs before. Is there a way to filter them by port or anything? I’m really not interested in any queries outside port 53.
That said,
if
nslookup google.com 8.8.8.8
Succeeds and
nslookup google.com
fails, that means that something is going wrong on the EC2 side, right? The latter is clearly not sending a DNS query to 8.8.8.8 despite what my resolved.conf says.
I did try searching 53,but that’s unfortunately too generic a string to meaningfully filter results. (Even on a test environment, it’s still a lot of hosts generating a lot of traffic)
It’s been a minute since I’ve played with these, but couldn’t you just hack it out by manually editing your resolv.conf, adding the dns entries, then doing a “chattr +i /etc/resolv.conf” to make it immutable so no process can write to it?
Not sure if it’d do more harm than good, but might be worth a try.
I found it. I had my resolver returning BLOCK > NODATA for domains that weren’t in the allow-list. NODATA responses are considered a successful hit by systemd-resolve’s LLMNR system, so that created a race condition between the resolver and the public DNS.
Setting the resolver to default to BLOCK > NXDOMAIN fixed it.