Writing a new answer as so many are just wrong.
https://netplan.readthedocs.io/en/stable/howto/ :
"To configure Netplan, save configuration files in the /etc/netplan/ directory with a .yaml extension (e.g. /etc/netplan/config.yaml), then run sudo netplan apply."
The installation/system may have already added a file (such as 50-cloud-init) to this area.
50-cloud-init.yaml, 00-installer-config.yaml should be overridden not edited:
To correctly update the netplan area to use a static IP over the default DHCP:
Create a new file (the prepended number+dash and .yaml extension are important).
Example:
sudo nano /etc/netplan/99-custom-network.yaml
Add your properly formatted YAML to this file.
A static IP example:
network:
ethernets:
ens160:
dhcp4: false
addresses: [10.10.10.5/24]
gateway4: 10.10.10.1
nameservers:
addresses: [10.10.10.100,8.8.8.8,8.8.4.4]
version: 2
Note: My network device is "ens160" - not "eth0" - adjust as needed.
Save new file.
Then run sudo netplan apply.
Make sure your network interface looks right and is working using ip ad / ping.
Reboot and retest. The host should be set to a static address. DONE.
Simply delete, or rename your file and rerun 'netplan apply' to restore previous settings.
More Information
Consult man netplan-generate for the rules governing how the network configurations are read from /etc/netplan/*.yaml (and elsewhere).
Adding your own file follows the netplan.io instructions as well as the general rule of not editing any existing/installed files when possible. In /etc/netplan/ and similar conf.d/ type config areas you should always opt for a high numbered custom/new file (when possible) instead of editing any installer and/or package files.
It's why they have numbered files in these configuration areas (in /etc/netplan/ and others). The higher the number on the file equates to when it is read in. Therefore, something with "99-" prepended on it will generally be read in last and OVERRIDE anything that repeated before it. Therefore, if a network interface is set to DHCP in "00-installer-config.yaml", and/or "50-cloud.init.yaml", the settings for the same interface in a "99-*.yaml" file will override everything else read in previously.
Generally these YAML files will NOT get overwritten, but that isn't valid logic to not follow the conf.d "standard" of using custom files to override and avoid editing any installed files. It doesn't take any extra time. Drop a file in netplan. Done. So, there's no excuse as I have witnessed in comments of "well, it's worked so far..".
So, editing the default netplan *.yaml(s) will technically "work", but you should create your own when possible.