Since Ubuntu 18.04+, netplan has become the default network configuration utility to define network interfaces.

I was creating a VM running Ubuntu 24.04.03 LTS in my homelab proxmox node and I wish to configure static IP on the VM. The steps to configure is actually pretty straight forward.

Edit the file at /etc/netplan/50-cloud-init.yaml:

network:
  version: 2
  ethernets:
    ens18:                   ## your interface may differ
      dhcp4: false
      addresses:
        - 10.0.0.99/24        ## your desired static ip and CIDR
      routes:
        - to: default         ## this will be your default route
          via: 10.0.0.1       ## your gateway for the subnet
      nameservers:
        search:
          - alexlogy.local    ## your local domain suffixes
        addresses:
          - 10.0.0.1          ## your desired dns servers

After saving the yaml file, apply the updated configuration

sudo netplan apply

You should be able to see your static ip configured successfully with the following commands

ip addr
ip route show

Sample output is shown below with sensitive information obfuscated:

alexlogy@homelab-01:~$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    altname enp0s18
    inet 10.0.0.99/24 brd 10.0.0.255 scope global ens18
       valid_lft forever preferred_lft forever
alexlogy@homelab-01:~$ ip route show
default via 10.0.0.1 dev ens18 proto static
10.0.0.0/24 dev ens18 proto kernel scope link src 10.0.0.99

For more custom configuration, you can refer to the official documentations for netplan at https://netplan.readthedocs.io/en/0.107/examples/.