If you have Dekstop version with network manager installed:
nmcli dev show | grep DNS
A better way for servers:
cat /etc/resolv.conf will give you
because Ubuntu uses dnsmasq, resolvconf, or more recently systemd to get it’s name servers from Network Manager.