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:
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:
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
Related videos on Youtube
alanwj
Updated on September 18, 2022Comments
-
alanwj over 1 year
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 withsystemd-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?
-
nucc1 about 6 yearsYou may find the answer here helpful unix.stackexchange.com/questions/136117/…
-
alanwj about 6 yearsI 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.
-
nucc1 about 6 yearsI 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 about 6 yearsof 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.
-
-
Chris over 5 yearsI 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)
-
trcm about 5 yearsI fixed this by uninstalling netplan and just using /etc/systemd/network/*.network files to configure networking accordingly.
-
Giovanni Toraldo about 4 yearsThis is working on ubuntu 18.04 right now (netplan 0.98)
-
timbo about 4 yearsCool. I see that 19.10 uses netplan 1.10.1 so issue should be resolved there too
-
Gaia almost 4 yearsWorks on 18.04, netplan/bionic 1.10.1-5build1