Can netplan configured nameservers supersede (not merge with) the DHCP nameservers?

Solution 1:

This has been fixed in the netplan repository on github, and will presumably make its way into Ubuntu at some point.

Two new options have been added, dhcp4-overrides and dhcp6-overrides. To ignore DNS servers from DHCP you would do something like:

dhcp4: yes
dhcp4-overrides:
  use-dns: no

Solution 2:

There is unfortunately no changelog in the netplan github repo to ascertain when the newer features came in. However there was a big jump in release versions in https://github.com/CanonicalLtd/netplan/releases from 0.40 to 0.90 in November 2018

On Ubuntu 18.10, netplan is presently at version 0.40.2.2

With that netplan version, trying a wireless config to do DHCP but with the Cloudflare anonymous DNS servers:

network:
  version: 2
  renderer: NetworkManager
    ethernets:
      wlp4s0:
        dhcp4: yes
        dhcp4-overrides:
          use-dns: no
        nameservers:
          addresses: [1.1.1.1,1.0.0.1]

produces an Unknown key dhcp4-overrides error:

enter image description here

There are no backports to cosmic according to ubuntu.packages.org

On Ubuntu 19.04 beta, netplan version 0.96 is installed and the dhcp4-overrides can be used:

enter image description here

Solution 3:

This is a really common setup that's totally borked in Ubuntu 18.04, Netplan needs to support the NetworkManager options when using DHCP:

nmcli connection modify ${ID} ipv4.ignore-auto-dns yes
nmcli connection modify ${ID} ipv4.dns 'xx.xx.xx.10 xx.xx.xx.20'
nmcli connection modify ${ID} ipv4.dns-search 'abc01.domain.com. abc02.domain.com.' 

Solution 4:

Using dhcp6-overrides with 'use-dns: false' doesn't work to ignore DNS servers provided over DHCP6.

NB: I'm using netplan.io 0.96 and systemd 240 in Ubuntu 19.04 (disco).

# cat /etc/netplan/10-enp3s0-init.yaml
network:
    version: 2
    renderer: networkd
    ethernets:
        enp3s0:
            critical: true
            dhcp4: true
            dhcp4-overrides:
                use-dns: false
            dhcp6: true
            dhcp6-overrides:
                use-dns: false
            ipv6-privacy: true
            nameservers:
                search: [home]
                addresses: [1.0.0.1, 1.1.1.1]

# resolvectl status enp3s0
Link 2 (enp3s0)
      Current Scopes: DNS
DefaultRoute setting: yes
       LLMNR setting: yes
MulticastDNS setting: no
  DNSOverTLS setting: opportunistic
      DNSSEC setting: yes
    DNSSEC supported: yes
  Current DNS Server: 1.0.0.1
         DNS Servers: 1.0.0.1
                      1.1.1.1
                      fd50:a94:67b3:0:26a7:dcff:fe27:a60 <--- DHCP6 provided?
          DNS Domain: home