Trouble Overriding DNS Servers via Netplan Config

I'm trying to override the nameserver settings in the netplan yaml configuration, but it doesn't seem to be working. Here's the /etc/netplan/01-netcfg.yaml file:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: yes
      dhcp4-overrides:
        use-dns: no
      nameservers:
        addresses: [192.168.1.7]

I'm running Ubuntu 18.04.3 LTS (I changed the nameserver IP address, but everything else is the same). Also, when I run netplan --debug generate, it produces this:

** (generate:1951): DEBUG: 20:05:57.212: Processing input file /etc/netplan/01-netcfg.yaml..
** (generate:1951): DEBUG: 20:05:57.212: starting new processing pass
** (generate:1951): DEBUG: 20:05:57.212: eth0: setting default backend to 1
** (generate:1951): DEBUG: 20:05:57.212: Configuration is valid
** (generate:1951): DEBUG: 20:05:57.212: Generating output files..
** (generate:1951): DEBUG: 20:05:57.212: NetworkManager: definition eth0 is not for us (backend 1)

And the really confusing thing is that there isn't any /run/netplan directory...

I should also mention that this is a virtual private server, so I don't have access to the bare metal... Not sure if that's important... Also, the reason that I'm using eth0 is because that's the only one that shows up when I run ifconfig, other than the loopback address. The original /etc/netplan/01-netcfg.yaml file from when I got the server from the hosting company was:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: yes

I wanted to reconfigure it so that I could use another virtual private server as the DNS server...

EDIT Just wanted to mention the output of systemd-resolve --status shows that the DNS Servers are the original ones configured by DHCP, and not the one overridden by the netplan configuration above. It doesn't seem to be accepting the netplan settings.

EDIT 2 In answer to some of the questions posted in the comments, I believe the hosting company has installed Ubuntu Server rather than a desktop installation. As far as I know, I can only access the VPS through a terminal, and I don't believe I have access to a GUI desktop. As for the other questions, I've reverted back to the original /etc/netplan/01-netcfg.yaml file and rebooted the server. Now, it should be back to its original configuration:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: yes

Also, it doesn't look like dhclient is running when I do ps aux | grep -i dhc... How can the /etc/netplan/01-netcfg.yaml file have dhcp4: yes configured if dhclient isn't running on the machine?

When I run ip a, I get

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
     ...
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
     ...

But there's no mention of enp0s3... Similarly for the ifconfig command, it just mentions eth0 and not enp0s3...

Here's the /etc/resolv.conf file:

# 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.
#
# 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 <Some loopback IP>
options edns0
search home

I changed the value of the nameserver above as well as the value of the seach option.

systemd-resolve --status includes the following at the bottom of its output:

Link 2 (eth0)
      Current Scopes: DNS
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
         DNS Servers: <IP1>
                      <IP2>
                      <IP3>
          DNS Domain: <domain1>

where IP1, IP2, and IP3 are three IPv4 addresses that I would prefer not to use for DNS, and domain1 is a domain name that I also have no use for. Please let me know in the comments if there's any other useful information that could be find. Should I configure a static IP in /etc/netplan/01-netcfg.yaml, since dhclient isn't running? Another question, wouldn't it make more sense to use eth0 for the network device instead of enp0s3, since the latter isn't present when ip a is run?

EDIT 3 It might be useful to know that the servers in question are being provided by Linode. I deactivated their Linode Network Helper in order to set up my own DNS servers. Just thought it be useful information to know... It should just be a regular Ubuntu 18.04 server.

Response to Update 1 - See Heynnema's response

So, after rebooting with /etc/netplan/01-netcnf.yaml as

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: yes
      dhcp4-overrides:
        use-dns: no
      nameservers:
        addresses: [ 192.168.1.7 ]

and /etc/systemd/resolved.conf as

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details

[Resolve]
#DNS=
DNS=192.168.1.7
#FallbackDNS=
#Domains=
Domains=mydomain.com
#LLMNR=no
LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes

I have the following:

/run/resolvconf/resolv.conf isn't present on the system.

cat /run/systemd/resolve/resolv.conf produces:

# 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.7
nameserver IP1
nameserver IP2
# Too many DNS servers configured, the following entries may be ignored.
nameserver IP3
search mydomain.com <domain1>

where IP1, IP2, and IP3 match those in the original output of systemd-resolve --status.

cat /run/systemd/resolve/stub-resolv.conf produces:

# 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.
#
# 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 127.0.0.53
options edns0
search mydomain.com <domain1>

Also, dpkg -l *dnsmasq* | grep ii produces:

ii  dnsmasq-base     2.79-1       amd64        Small caching DNS proxy and DHCP/TFTP server

and dpkg -l *dhcp* | grep ii produces:

ii  isc-dhcp-client      4.3.5-3ubuntu7.1 amd64        DHCP client for automatically obtaining an IP address
ii  isc-dhcp-common      4.3.5-3ubuntu7.1 amd64        common manpages relevant to all of the isc-dhcp packages

However, when I run ps aux | grep dns and ps aux | grep dh, no results are returned other than grep itself.

Edit 4

In case anyone's interested, the contents of /etc/systemd/network/05-eth0.network, minus the comments, were:

[Match]
Name=eth0

[Network]
DHCP=no
DNS=IP1 IP2 IP3
Domains=<domain1>
IPv6PrivacyExtensions=false

Gateway=the_gateway_ip
Address=my_public_ip
Address=my_private_ip

where IP1, IP2, and IP3 were the nameserver IPs that I needed to override, and domain1 was a domain name created by the hosting provider. The Gateway and two Address settings were the correct ones that I needed. I just wanted to override the DNS settings, so renaming the file to avoid its being used did the trick.

Many thanks in advance!


Solution 1:

For a minimalist effective solution try this :

sudo systemctl stop systemd-resolved
sudo systemctl disable systemd-resolved

Now delete the link /etc/resolv.conf and create the /etc/resolv.conf as a plain text file listing only the DNS servers you want to use, for example

nameserver 192.168.1.7
search mydomain

Where mydomain is a local domain declared in your local DNS config. Example : in /etc/bind/zones (depending on your bind config)

If your device is mobile then your local DNS will fail of course so I include in my resolv.conf

 nameserver 1.1.1.1
 nameserver 1.0.0.1

... i.e the Cloudfare servers for example.

I find that with this setup the netplan DNS config is ignored.

This approach has been working for me without issue through the last few releases of Ubuntu.

I do this because systemd-resolve insists on listing my ISP DNS servers -- which I do not want to use.

Solution 2:

I called the hosting provider, and they directed me to look at two configuration files. One was the netplan configuration file that I was aware of, but the other was /etc/systemd/network/05-eth0.network. After renaming the file by placing a . in front of its name and then rebooting the server, the changes that had been made to /etc/netplan/01-netcfg.yaml took affect for device eth0. I added the contents of the file to the last update in the question, in case it can help anyone.

Solution 3:

Change your .yaml file back to the eth0 version that you had before...

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: yes
      dhcp4-overrides:
        use-dns: no
      nameservers:
        addresses: [192.168.1.7]
  • sudo netplan --debug generate
  • sudo netplan apply
  • reboot

/etc/systemd/resolved.conf should probably be edited to look something like this...

[Resolve]
DNS=192.168.1.7
#FallbackDNS=
Domains=put_your_domain_here
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=yes
#DNSStubListener=yes
#ReadEtcHosts=yes

reboot

systemd-resolve --status

Update #1:

Let's check the three possible symlinks for /etc/resolv.conf...

Using the eth0 .yaml file... and the modified /etc/systemd/resolved.conf... after a reboot...

Show me...

cat /run/resolvconf/resolv.conf

cat /run/systemd/resolve/resolv.conf

cat /run/systemd/resolve/stub-resolv.conf

Update #2:

Assuming that the dhcp4-overrides is broken, let's try this .yaml...

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses: [x.x.x.x/24]
      gateway4: x.x.x.1
      nameservers:
        addresses: [192.168.1.7]
        search: [mydomain, otherdomain]

sudo netplan --debug generate

sudo netplan apply

reboot

systemd-resolve --status