18

I know that systemd-resolve --status lists all my connections and their DNS servers and nmcli connection show <connection> | grep -i dns will list the priority of the DNS connections. But is there a single command I can run that will list all DNS servers and their priority/order?

chizou
  • 313

2 Answers2

26

It is stupid, but you can't!

systemd-resolved follows internal rules to choose the "correct" DNS. This might be different for each query. It uses things like if a server worked or failed in the past, interface order and even what domains allocated to each interface. It's difficult to manage with some VPN setups.

The best you can do is to cat /run/systemd/resolve/resolv.conf to see the resolv.conf file generated by systemd-resolved.

Per Lundberg
  • 161
  • 7
higuita
  • 2,101
  • 2
    I also gave up and install dnsmasq with rules to resolve some domains in certain servers (ie: internal DNS to the internal network dns server). This solved my problems using several VPNs and dns resolve order – higuita Jan 30 '20 at 20:48
  • Why o why am I not surprised that linux developers, who after 20 years still can't make a properly functional desktop that isn't littered with bugs and inconsistencies, can't make a properly functional command line interface also. It's so depressing. Open Sores indeed. – Christopher Thomas Aug 15 '22 at 20:38
  • @ChristopherThomas notice that all OS have weak and strong points, having used both windows and macosX, i can tell you that they both have lot of stupid "features" in the DNS. I understand that systemd was developed for the clueless user and it tries to guess things... but still, not all users are clueless and having only that operating node is stupid.The problem is that there is no "one size fits all" and that is why all OS have major issues with managing DNS. That being said, while not perfect, IMHO, linux is still a much better OS and desktop than the other two, and it's free and open – higuita Aug 18 '22 at 02:39
  • systemd's command line interface is absolute garbage. It lacks many features that would be useful for people building interfaces to automate and control a linux system through user interfaces, etc. But it just doesn't have them. They only implemented the basic functionalities and missed a lot of what actual system administrators need. We don't want to parse weird and wacky command line outputs using sed or grep for some value. I expect to be able to query the value and get it directly. It's absolute garbage. Even knowledgable administrators suffer to get useful information out of it. – Christopher Thomas Aug 19 '22 at 10:02
  • and by the way, mac does not have problems managing DNS and has had a consistent command line interface for years already and it's stable and reliable. So your claim that all OS have this issue is false. Windows also has a stable way to interact with it's networking system through the command line. Linux is the only one out of those three with problems. – Christopher Thomas Aug 19 '22 at 10:04
  • systemd-resolv got self-awareness, it just doing things, not care what you want – yurenchen Nov 27 '22 at 05:03
  • @ChristopherThomas there's no way you just implied Windows has a better CLI experience than Linux – Matthew Strasiotto Jan 23 '24 at 04:52
  • You're right, I didn't imply that. What I said was that the windows tools to interacting with the network subsystem is at least stable and useful without parsing text for little snippets of text in a fragile way which linux requires to do the same job – Christopher Thomas Jan 29 '24 at 16:20
0

It is possible to make a dns priority with

nmcli -p connection modify MY_VPN_CONNECTION ipv4.dns-priority -42

as taken from https://github.com/systemd/systemd/issues/6076

abu_bua
  • 10,783
Kerya
  • 41