How to set a static IP in ubuntu 20.04 & 22.04

Today, I will explain how you can set a static IP in ubuntu 20.04 and 22.04.

The first thing we will want to do is edit the file located at /etc/netplan/, this file might have a different name depending on what computer you are using. You can use the key tab on your keyboard after typing /etc/netplan/. Once you know the file edit it with your favorite text editor.

sudo nano /etc/netplan/[your_file]

Once you open it, you should see something like this:

network:
    version: 2
    renderer: networkd
    ethernets:
        enp3s0:
            dhcp4: true

Now, we will proceed to change the parameters for a static IP, I will leave a template that you can follow for ubuntu 20.04 and 22.04.

20.04:

network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      dhcp4: false
      dhcp6: false
     addresses:
      - 192.168.10.10/24
     gateway4: 192.168.10.1
     nameservers:
      addresses: [192.168.10.1]

22..04:

network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      dhcp4: false
      dhcp6: false
     addresses:
      - 192.168.10.10/24
     routes:
      - to: default
        via: 192.168.10.1
     nameservers:
       addresses: [192.168.10.1]