168 points · by belter · 5y ago · 49 comments
Anatomy of a Linux DNS Lookup – Part II https://zwischenzugs.com/2018/06/18/anatomy-of-a-linux-dns-l...
Anatomy of a Linux DNS Lookup – Part III https://zwischenzugs.com/2018/07/06/anatomy-of-a-linux-dns-l...
Anatomy of a Linux DNS Lookup – Part IV https://zwischenzugs.com/2018/08/06/anatomy-of-a-linux-dns-l...
Anatomy of a Linux DNS Lookup – Part V – Two Debug Nightmares https://zwischenzugs.com/2018/09/13/anatomy-of-a-linux-dns-l...
Then you can hit DNS request hopping between servers too: https://github.com/systemd/systemd/issues/19209
resolv.conf would use the first one, and then timeout and use the next one
Nice and simple.
The quote
"simply turn off systemd-resolved"
Is usually the answer, but it's a constant uphill battle to fix broken behaviour.
Of course Pottering doesn't care.
Relying on resolv.conf meant using the first one unless it times out, which makes it impossible for me to connect to two private networks with their own hostname resolution, if a hostname resolves in both but to different addresses.
The behavior of the 'dns' module is terrible. If you have three servers listed and the first one is unavailable then every. single. dns. request. must wait for the first server to time out then try the second one.
Also if you have three servers listed and server 3 happens to be the fastest you'll never know because even if the first two servers are down and you finally use it there are two timeouts in between you and that speed.
And since there's only one resolv.conf if you're connected to a split-tunnel VPN you get to choose whether to send all your DNS requests over the tunnel or none of them.
systemd-resolved actually does the right thing in (almost) all of these cases. Built-in kernel IPSec still trips it up because systemd-resolved's view of the world is mapping DNS configuration to interfaces and since kernel IPSec is a policy VPN blah blah nevermind -- it has memory so it can remember if servers are down, and it used to send requests to all listed servers to find the fastest one and prefer it before people complained, and split-tunnel VPNs work!
The "feature" of "merging" DNS zones by relying on query order is pants on head broken as soon as your first DNS server is unreliable or if your first server doesn't return a strict superset of all subsequent servers. If you have internal names both over your VPN and on your local network then no matter what order you pick one of them will be unresolveable.
Pottering, in that thread, literally says
"I have the suspicion that this going to negatively affect about as many people as it positively affects..."
https://askubuntu.com/questions/907246/how-to-disable-system... is a "good" solution to the problem in ubuntu
https://tailscale.com/blog/sisyphean-dns-client-linux/
and corresponding HN: https://news.ycombinator.com/item?id=26821298
* disclaimer: I have no affiliation w/ Tailscale. I just wish I did.Edit: Well, and also browsers doing DNS over https. It's pretty confusing these days to know which path your app took to resolve a name.
Writing those posts was incredibly cathartic, but I still left stuff out because I couldn’t get to the bottom of it. I do recall that configuring systemd resolved and finding useful docs for it was a nightmare.
I've used Debian based distributions for 20 years with nothing more than ifupdown, resolvconf, and occasionally dnsmasq, but no distro for old men and all that.
Stuff like systemd (and systemd-resolved) are wonderful innovation and that m god they're the de-facto standard on most desktops.
And by the way, the joy of systemd-resolved is in complex stuff that become surprisingly easy.
Example: split-horizon DNS. You're connected to a VPN network but you're only routing some subnets through that, not everything. Thus, you have to have DNS that query some DNS server inside the VPN for a set of domains, but keep using the usual DNS servers for everything else.
It's surprisingly easy with systemd-resolved, but I'm not aware of any feasibility without a DNS server running on the local machine (albeit in resolver mode). Which usually would be dnsmasq, but at that point you might as well run systemd-resolved.
Why. I want to route 10.0.0.0/8 via a VPN, I don't know if "flargle.bazonga.com" resolves to 10.0.0.1 or 99.99.99.99 until I do the lookup.
Well I'm a shade over 50.
I use Arch on my laptop. I love the flexibility of NetworkManager and I use a variety of DNS sources including a local unbound and a /etc/hosts file. I have a wired ethernet profile called RFC1918 with a lot of addresses on it that covers pretty much all router, firewall and switch defaults. It crucially has the check box for "Use only for connections..." in the routes section. That means that the default gateway stays on the wifi and/or VPN. I have several other profiles to deal with various combinations of requirements.
Recently I modelled a data centre on my home network to get a Fortigate cluster up and running as though it was in place. It's WAN was behind a VLAN on my home pfSense, so it had it's "real" external IPs running fine and then I put VMs in at various places to test out routing and policy before deployment.
DNS is simply (lol) a name to address mechanism and there is no need to get too het up about it. I simply make whatever view of the world I need to exist at the time I'm doing a job. I do this for IPv4 and 6.
It can get a bit challenging WFH. I have a site to site IPSEC VPN to the office and also a OpenVPN dial up VPN connection available. Customer sites are generally setup to allow access from certain IPs and I have to make sure I appear to be the right address. Even more fun is had with the quite large collection of sites with a subnet range of 192.168.{0|1}.0/24. Those I generally wholesale NAT and then for the really dumb devices at the other end or those with a broken routing table, NAT outbound on LAN.
"My eyes are bent my back is grey ..."
Bloody kids 8)
I wrote a small gist on the setup a couple years ago that is still mostly relevant. In case you're interested... https://gist.github.com/eikenb/1e9faeb8210e639e8caa69e9832db...
Now of course I can return to basics and learn everything again from scratch. The problem with that approach is distros like Ubuntu frequently drop in new features which last 5 years, and then they're gone as they're no longer sexy. This reduces the payoff of learning something new, may as well just continue to fight.
I probably won't use ubuntu on servers going forward as they broke the installer for 20.04 (they got rid of the nice simple debian-installer, which just needed a new kernel/initrd and a preseed tweak every 2 years) and replaced it with some live cd monstrosity. Managed to avoid netplan on 18.04. It's a pain, as it means spending mental effort to make changes to something that just works, and the whole reason I use linux is because it has "just worked" for 2 decades.
It seems all these recent changes are aimed at people who want their linux machine to operate just like an OSX laptop.
I feel like the DNS situation is way too complicated, I really don't even know where the tunnel ends anymore. I resulted to using the GUI and hope it handles everything, which I hate because I want to understand what's happening under the hood. I felt powerless
[1] https://kubernetes.io/docs/tasks/administer-cluster/nodeloca...
see https://github.com/azukiapp/libnss-resolver - it's an NSS lib just like libnss_dns or libnss_files, which looks up resolv.conf-style files according to the queried domain suffix.
it's not a deamon.
i integrated it with dhcp client and ifup/down and use it happily for years.
disclaimer: i contributed to libnss_resolver.
most of them do not contribute in building better solutions, which help more people then themselves. just blabbering on and requiring stuff which only works for THEIR usecase. this is really annoying at times.