Ubuntu server 22.04 how do I determine what DNS server is in use from the command line?

I’ve already read the link here. I tried this from the accepted answer
nmcli device status
but I get this result
sudo: nmcli: command not found.
Then I read this link. I tried this
systemd-resolve --status | grep 'DNS Servers'
but I get this result
sudo: systemd-resolve: command not found.

Does anyone know a command that will work on 22.04?

Asked By: CB_Ron

||

With Ubuntu Server 22.04, networking is managed with systemd-networkd (not NetworkManager). Configure your network settings with Netplan

DNS name resolution is provided by a service called systemd-resolved. It offers DNS resolution via a D-Bus interface, the resolve NSS service (nss-resolve(8)), and a local DNS stub listener on 127.0.0.53. If you run the command, cat /etc/resolv.conf, you’ll see that it lists 127.0.0.53 as the DNS server. This is the local stub resolver.

$ cat /etc/resolv.conf
# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
options edns0 trust-ad
search localdomain

When you run the command, ls -l /etc/resolv.conf, you’ll see that it links to a file the defines the local stub resolver:

$ ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 37 Mar 20 10:16 /etc/resolv.conf -> /run/systemd/resolve/stub-resolv.conf

This is normal behavior. It caches DNS queries locally to resolve. If a query is not in the cache, then it will query any uplink DNS servers that have been delivered via DHCP or manually defined in your Netplan configuration file. To see what your uplink DNS servers are, run resolvectl status:

$ resolvectl status
Global
       Protocols: -LLMNR -mDNS -DNSOverTLS
                  DNSSEC=no/unsupported
resolv.conf mode: stub

Link 2 (eth0)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS
                DNSSEC=no/unsupported

Link 3 (eth1)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS
                DNSSEC=no/unsupported

Link 4 (bond0)
    Current Scopes: DNS
         Protocols: +DefaultRoute +LLMNR -mDNS
                    -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.10.1
       DNS Servers: 192.168.10.1
        DNS Domain: localdomain
Answered By: mpboden