1

I have a couple netplan config files, one that configures the machine statically

# /etc/netplan/02-static-config.yaml
network:
    ethernets:
        enp0s3:
            addresses:
              - {my static IP}
            gateway4: {my gateway}
            nameservers:
                addresses:
                  - { some }
                  - { DNS servers }
            dhcp4: false
    version: 2

and one that very simply configures it to use DHCP

# /etc/netplan/03-dhcp-config.yaml
network:
    ethernets:
        enp0s3:
            dhcp4: true
            addresses: []
    version: 2

I then wrote a couple shell scripts that renames the DHCP script to either 01 (if I wanted statics) or 03 (if I wanted DHCP), then called netplan generate and netplan apply.

Unfortunately, although the docs seem to imply that the addresses mapping from 03-dhcp-config.yaml should override 02-static-config.yaml:

Lexicographically later files (regardless of in which directory they are) amend (new mapping keys) or override (same mapping keys) previous ones. ed: emphasis mine.

what I'm actually seeing is that both addresses bind to the same interface.

username@machine:~$ ip address show enp0s3
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:6d:2c:d6 brd ff:ff:ff:ff:ff:ff
    inet {my static IP} brd {a bridge} scope global enp0s3
       valid_lft forever preferred_lft forever
    inet {a DHCP address} brd {and associate bridge} scope global secondary dynamic enp0s3
       valid_lft 691170sec preferred_lft 691170sec
    inet6 fe80::a00:27ff:fe6d:2cd6/64 scope link
       valid_lft forever preferred_lft forever

How can I make 03-dhcp-config.yaml override 02-static-config.yaml? Or alternatively: how can I disable 02-static-config.yaml quickly and easily?

Adam Smith
  • 161
  • 5
  • Note: this is crossposted from [here](https://superuser.com/questions/1355643/netplan-overwrite-previous-config) not sure if this is more in-line with superuser or server fault! – Adam Smith Sep 05 '18 at 23:46
  • It is valid for an interface to have both static and DHCP assigned addresses. But the old Debian interfaces file had no way to represent this configuration, so most Debian/Ubuntu users never configured this, or even knew it was possible. – Michael Hampton Sep 06 '18 at 01:23
  • @MichaelHampton right, and that's cool info, but isn't the way I'm trying to configure my system! I would think that specifying `addresses: []` in the DHCP config would override the `addresses: [{my static IP}]` line in the static config, but it's not. – Adam Smith Sep 06 '18 at 02:36
  • Aha, I see what you're saying. It could possibly be a bug. Of course, netplan is pretty much pointless garbage anyway, so you might just want to get rid of it and write the systemd-networkd configs yourself. – Michael Hampton Sep 06 '18 at 12:24

0 Answers0