1

I am currently working on ubuntu 20.04 machine.

What is exactly a DNS resolver/nameserver associated with a network interface? when i am checking the /etc/resolv.conf file, i can see nameserver 127.0.0.53 and when i check the resolvectl status, i am getting DNS Servers: 172.31.0.2 for the network interface (eth0) of my instance. My instance's network interface is configured with dhcp4: true

  1. Why there are two different outputs? How is this related?
  2. Is the DNS server output 172.31.0.2 i got from resolvectl status command is dynamically assigned to eth0 by DHCP? If not, Is there anyway i can see the DNS resolver IP provided by DHCP?

1 Answer 1

3

127.0.0.53 is the DNS stub resolver, which is a local DNS caching server. If you type in the following command, you'll see that /etc/resolv.conf is a symlink pointing to /run/systemd/resolve/stub-resolve.conf.

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

Then, if you look at the contents of that file, it will show 127.0.0.53 as the DNS server.

$ 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 .

The other DNS server, 172.31.0.2, is provided to your computer via DHCP and is automatically added to /run/systemd/resolve/resolv.conf. This is your uplink server.

If you prefer to use the uplink server, you can simply delete the current symlink that points to the stub resolver and create a new one to this file.

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

Either way, if you run a dig command, you'll see which DNS server is actually being used. On my system:

$ dig google.com

; <<>> DiG 9.18.12-0ubuntu0.22.04.1-Ubuntu <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52917
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             213     IN      A       142.250.72.142

;; Query time: 3 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Thu Apr 06 10:59:05 PDT 2023
;; MSG SIZE  rcvd: 55

Notice that it's specifying 127.0.0.53. That's because my /etc/resolv.conf is a symlink to /run/systemd/resolve/stub-resolv.conf.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .