Score:2

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

gr flag

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?

cc flag
systemd-resolve is obsolete, and not normally a part of 22.04. The nmcli comand is from package network-manager, is that installed?
CB_Ron avatar
gr flag
@ubfan1 no, it is not. Trying it now.
CB_Ron avatar
gr flag
@ubfan1 I installed network-manager, now when I run `sudo nmcli device status` all devices have `unmanaged` under `STATE` and no other data.
ar flag
@ubfan1 I have a few fresh instant of Ubuntu 22.04 and 23.04 in VMs. As far as I can see systemd-resolve.service is active and running. It is very much a part of Ubuntu desktop installations.
ar flag
`resolvectl status` works for me.
cc flag
@user68186 The program systemd-resolve is not the deamon, systemd-resolved, but since the name caused much confusion, I can see why it was removed (replaced by resolvectl).
Score:3
do flag

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
CB_Ron avatar
gr flag
Thank you, this makes sense and is in fact giving me the information I wanted.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.