Netplan example script for static IP on Ubuntu Server 20.04+

Netplan stores it's config files in /etc/netplan. The installer will create a starter script that enables dhcp on the interface by default. In my system, the Ubuntu Server 20.04 installer created a file called 00-installer-config.yaml, below is the file from a fresh install.

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp1s0:
      dhcp4: false
  version: 2
#edit your existing yaml file, adding the lines below.

network:
  ethernets:
    enp1s0:
      dhcp4: false # change this to false
      addresses: [192.168.2.x/24] # change to your needed ip/subnet
      routes: # add default route since gateway4 is depreciated
        - to: default
          via: 192.168.2.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]
  version: 2
  renderer: networkd



Each system will have a different interface name, so it's best to use

   ip link or ip ad to find your interface name.

Once you save the file, run netplan apply to enable the new configuration.