How to get netplan to replace sections instead of merge?

505 views Asked by At

I am trying so set netplan so the yaml files only contain portions of the configuration. The idea is to use a specific config file when a machine should use a specific DNS.

In order to do that, I have 2 yaml config files: /etc/netplan/01-netcfg.yaml and /etc/netplan/02-dns.yaml'

Their content is really simple. /etc/netplan/01-netcfg.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: true
      dhcp6: false
      optional: true
      nameservers:
        addresses: [4.2.2.1, 4.2.2.2, 208.67.220.220]

and /etc/netplan/02-dns.yaml:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      nameservers:
        addresses: [1.1.1.1]

When I apply the configuration and check the DNS configuration, I get the following:

# systemd-resolve --status
Global
[...]
  Current DNS Server: 4.2.2.1
         DNS Servers: 4.2.2.1
                      4.2.2.2
                      208.67.220.220
[...]
Link 2 (eth0)
[...]
  Current DNS Server: 4.2.2.1
         DNS Servers: 4.2.2.1
                      4.2.2.2
                      208.67.220.220
                      1.1.1.1
                      10.0.2.3

So it appears that the configurations got 'cumulated': the DNS from the 02xxx file got added to the DNS from the 01xxx file (which makes sense...).

How to I get net plan to 'replace' instead of 'merge'?

0

There are 0 answers