Table of Contents

Ubuntu - Networking - DNS - /etc/resolv.conf

DANGER: Do not manually make changes to /etc/resolv.conf.

  • Any changes will be overridden, since Ubuntu 12.04.
  • /etc/resolv.conf is nowadays maintained by systemd.
  • If DNS resolver changes are needed then do this through systemd.

List /etc/resolv.conf

ls -al /etc/resolv.conf

returns:

lrwxrwxrwx 1 root root 32 Jan 10 18:50 /etc/resolv.conf -> /run/systemd/resolve/resolv.conf

NOTE: This shows that /etc/resolv.conf is a symlink to /run/systemd/resolve/resolv.conf.

It may instead be a symlink to /run/systemd/resolve/stub-resolv.conf. Also ok.

If not then to fix try:

sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Display /etc/resolv.conf

cat /etc/resolv.conf

returns:

# 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 192.168.1.1
search localdomain

NOTE: If the nameserver is 127.0.0.53 then this is fine too - It is set as default by Ubuntu.

Usually it would only show as 192.168.1.1 or similar if DNS changes had been made in networking settings; such as in /etc/netplan.


To Make Resolver Changes

Edit the /etc/resolvconf/resolv.conf.d/head file.

NOTE: Ignore the scary warning.

/etc/resolv.conf is auto-generated; so the warning is there so it will get put in /etc/resolv.conf when /etc/resolv.conf is generated.

To the end of the file, add:

/etc/resolvconf/resolv.conf.d/head
nameserver <ip_of_nameserver>

NOTE: Resolvconf has a /etc/resolvconf/resolv.conf.d/ directory that can contain “base”, “head”, “original” and “tail” files. All in resolv.conf format.

  • base: Used when no other data can be found
  • head: Used for the header of resolv.conf, can be used to ensure a DNS server is always the first one in the list
  • original: Just a backup of your resolv.conf at the time of resolvconf installation
  • tail: Any entry in tail is appended at the end of the resulting resolv.conf. In some cases, upgrading from a previous Ubuntu release, will make tail a symlink to original (when we think you manually modified resolv.conf in the past)

Regenerate /etc/resolv.conf so the changes are applied right now:

sudo resolvconf -u

Common DNS configuration changes

To make DNS configuration changes for some common use cases:

WARNING: Disabling resolvconf is not recommended, but you can replace the symlink /etc/resolv.conf with a regular file.


Test

setup nslookup or dig command:

dig www.google.com
nslookup www.google.com