17

I would like to use DHCP to assign an IP address to my server, but specify the DNS servers manually. I tried the following simple configuration:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: yes
      nameservers: [8.8.8.8,8.8.4.4]

After running netplan apply I check the nameservers with systemd-resolve --status and it shows:

DNS Servers: 8.8.8.8
             8.8.4.4
             192.168.1.1

The last is the DNS server provided by DHCP, which I do not want to be in the list.

Does netplan have a way to accomplish this?

4
  • You may find the answer here helpful unix.stackexchange.com/questions/136117/…
    – nucc1
    May 5, 2018 at 12:35
  • I appreciate the attempt to help, but dhclient.conf does not appear to affect netplan configured DHCP at all. In fact, on Ubuntu 17.10 I found that you could delete the dhclient binary and netplan would still configure everything with DHCP.
    – alanwj
    May 7, 2018 at 7:18
  • I found the bug (you?) filed on netplan for this: bugs.launchpad.net/netplan/+bug/1759014 I skimmed the netplan code and it doesn't support any way to specify DHCP options. It is hardcoded to write two options "UseMTU" and "RouteMetric". The only way I can think of for "hacking" what you want is to manually (or using a script) edit the files in /run/systemd/network/10-netplan-* which is where networkd reads definitions from. YOu can append the dhcp options you want there . doesn't look too complex to support this, so maybe we will see a patch in our lifetimes.
    – nucc1
    May 7, 2018 at 11:36
  • of course, as you know, the files will be overwritten every time you call netplan apply... also, my comments are based on Ubuntu 18.04 and the current Master of netplan.
    – nucc1
    May 7, 2018 at 11:45

4 Answers 4

14

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
2
  • 3
    I agree this is the best fix. However, if you don't have the latest netplan (for example, you're on 18.04 like me), you can instead append "UseDNS=false" to /run/systemd/network/10-netplan-*.network, then execute systemctl restart systemd-networkd. Note that a future netplan apply will clobber this. (Info from bugs.launchpad.net/netplan/+bug/1759014/comments/5)
    – Chris
    Jan 22, 2019 at 15:19
  • Works on 18.04, netplan/bionic 1.10.1-5build1
    – Gaia
    Jun 2, 2020 at 22:28
5

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

2
  • This is working on ubuntu 18.04 right now (netplan 0.98) Mar 9, 2020 at 8:34
  • Cool. I see that 19.10 uses netplan 1.10.1 so issue should be resolved there too
    – timbo
    Mar 9, 2020 at 20:12
2

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.' 
1

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
1
  • 1
    I fixed this by uninstalling netplan and just using /etc/systemd/network/*.network files to configure networking accordingly.
    – trcm
    May 6, 2019 at 9:44

You must log in to answer this question.

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