Netplan is a utility for configuring network devices using either NetworkManager or systemd-networkd.
We also remove the files netplan creates on start up:
Then we can reboot the system so that it reboots without netplan handling the network configuration.
When we do an "ip addr", the network interface will have no IP address.
We could also check using the below command:
We now create a file called "/etc/systemd/network/20-static-address.network".
The systemd.networkd service will use the above file, since it is the only file that exists in that directory:
Now, we check the interface using the "ip addr" command.
In case we want our interface to use "dhcp", we create another file as we see below - called "/etc/systemd/network/10-dhcp-address.network"-:
Since the "dhcp" file starts with a lower number -10-, it will take precedence over the static one that starts with the number -20-.
Then we restart our service:
[Match] : represents the interface to which networkd applies its settings.
[Network] : represents the setting of the network applied to interfaces.
We could keep both files -dhcp and static- and use the configuration that suits our needs by changing the priority of the files - which is based on the number that the file's name starts with -