4 ms·
It depends on what you're using for the resolver. I'm assuming you only care about gethostbyname(3) and friends. With glibc that means nss; generally you're als
by mdlowman 5y ago
It depends on what you're using for the resolver.
I'm assuming you only care about gethostbyname(3) and friends. With glibc that means nss; generally you're also looking at libnss_dns.so, which uses glibc's resolv (copied from BIND). This doesn't include enough configuration to do what you suggest; it pretty much just points everything towards a server.
So you have two options: use a different NSS module (maybe write your own?) or have a proxy DNS resolver that sends different requests to different places.
systemd-resolved actually handles the first option pretty well (although it would prefer that you use the dbus interface over gai). It can handle multiple interfaces with separate domains and split DNS fairly well! (Not so good with reverse DNS, unfortunately. But I get it, reverse DNS is pretty hacky anyways.)
If you prefer the forwarder route, dnsmasq seems to be fairly popular these days in the embedded world and elsewhere.
If I were you, I think I'd write a short NSS module or use dnsmasq, depending upon your needs.
- nine_k 5y agoIndeed, dnsmasq seems to be the least painful way to provide special DNS zones, special host files, and forwarding for everything else. Also, your resolv.conf becomes trivial. The trick is to grab the DHCP-provided DNS server address on reconnections and update the forwarding, if you use a laptop. For VMs in the cloud, it's not a problem, of course.