How to make persistent changes to /etc/resolv.conf Ubuntu 18.10

I am reproducing section "1.11.2. Configure /etc/resolv.conf file" from my answer Part-I Preinstallation: How to install Oracle 18c (Enterprise Edition) on Ubuntu 18.04?

To display what network interfaces are available in the system, issue the following command:

$ ip link show

enter image description here Figure-39: The WiFi network adapter wlp5s0 is active, up and running.

Network configuration file /etc/netplan/.yaml should be checked for configuration details. To display the contents of the file, issue the following command:

$ cat /etc/netplan/01-network-manager-all.yaml

enter image description here Figure-40: Network Manager file 01-network-manager-all.yaml is not configured yet.

Find out whether /etc/resolv.conf is a static file or symlink by the following command:

$ ls -l /etc/resolv.conf

enter image description here Figure-41: File /etc/resolv.conf is a symlink pointing to stub file 'stub-resolv.conf'.

In fact, @igor, the symlink what you removed from other post was really the link to stub file stub-resolv.conf.

After severed the symlink between /etc/resolv.conf and stub-resolv.conf which carried the nameserver 127.0.0.53, /etc/resolv.conf was left alone and it was you who made /etc/resolv.conf as a static file!

The fact is, @Igor, you were not really offered any solution by that act of severance.

Now, display contents of /etc/resolv.conf by the command:

$ cat /etc/resolv.conf enter image description here Figure-42: The contents of symlink '/etc/resolv.conf' having 127.0.0.53 as nameserver.

The dns shown by /etc/resolv.conf, is 127.0.0.53 but not the default nameserver configured for dhcp.

Issue the following command to find out the default dns server:

$ systemd-resolve --status wlp5s0

enter image description here Figure-43: The default DNS server for WiFi network adapter is 192.168.43.1.

Display contents of /run/systemd/resolve/resolv.conf, by the command:

$ cat /run/systemd/resolve/resolv.conf

enter image description here Figure-44: The contents of '/run/systemd/resolve/resolv.conf' indicating default nameserver.

From figure-44, you can observe that /run/systemd/resolve/resolv.conf is the one which really is carrying the default name server 192.168.43.1.

Issue the following command to change the symlink /etc/resolv.conf to point default dns server 192.168.43.1 instead of 127.0.0.53.

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

$ ls -l /etc/resolv.conf

enter image description here Figure-45: File /etc/resolv.conf is a symlink pointing to default nameserver.

After setting up sysmlink as shown in figure-45, you must make sure that your Wi-Fi is connected, up and running, by issuing the following command:

$ nmcli device

enter image description here Figure-45-a: Wi-Fi network interface adapter 'wlp5s0' is connected, up and running.

Conclusion:

Under the circumstances, the symlink is the not only best answer you got but also a decent and acceptable solution.


  1. First... remove your edits from /etc/network/interfaces.

  2. Next, we delete your static /etc/resolv.conf file and replace it with the original symlink...

In terminal...

cd /etc # change directory

sudo rm -i resolv.conf # delete static file

sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf # recreate symlink

Now DO NOT manually edit this file!

  1. Finally, set your DNS servers here...

Set DNS Automatic to OFF. Enter comma-separated DNS IP addresses.

enter image description here


td;dr

/etc/resolv.conf should not be edited by users

> cat /etc/resolv.conf # Ubutnu 18
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# 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 "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.

Network Manger has changed to "netplan" in Ubuntu 18
netplan's tool for managing DNS is systemd-resolve

* on the fly configuration *
1. check
sudo systemd-resolve --status eth0
eth0 is your interface

if there were no DNS servers, set it
2. set
sudo systemd-resolve --interface eth0 --set-dns 1.1.1.1
(you can add more using multiple --set-dns option)

* for persistent configuration *
Take look at ...
cat /etc/netplan/*.yaml

And example of a yaml file

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no
      addresses:
        - 192.168.121.199/24
      gateway4: 192.168.121.1
      nameservers:
          addresses: [8.8.8.8, 8.8.4.4]

See more
1. how-to-set-dns-nameservers-on-ubuntu-18-04
2. netplan

Also you can install "resolveconf" which is simpler
plus none of these are best, if your are managing a Server.
For Server take look at FreeBSD tool: relayd
or PowerDNS tool: dnsdist