Ubuntu 18.04 Server - how to check DNS IP server setting being used

I found the following showed my the DNS servers by adapter towards the end of the output:

systemd-resolve --status

It contains a list under 'DNS Servers' organized by Link. I think this has changed from previous versions with Ubuntu. It will take a little text parsing work but this gives me what I'm after.


You can also use:

nmcli dev show eth0

Replace eth0 with your network interface to see how it was configured. If you got the DNS address over DHCP, you should see it here.


Another way is:

cat /run/systemd/resolve/resolv.conf

That file is dynamically generated by systemd-resolved, but contains the actual DNS servers instead of 127.0.0.53.

In fact, if you want make that the default for /etc/resolv.conf, you simply create symlink for it. (/etc/resolv.conf is a symlink that points to /run/systemd/resolve/stub-resolv.conf by default):

sudo mv /etc/resolv.conf /etc/resolv.conf.orig
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

Sample /run/systemd/resolve/resolv.conf :

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs must 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 10.1.2.3
search host.domain.com

For more info:

http://manpages.ubuntu.com/manpages/bionic/man8/systemd-resolved.service.8.html